Why are many languages case sensitive?

后端 未结 30 1698
执念已碎
执念已碎 2020-11-29 04:35

Why are many languages case sensitive?

Is it simply a matter of inheritance? C++ is case-sensitive because C is, Java is case-sensitive because C++ is, etc.? Or is t

相关标签:
30条回答
  • 2020-11-29 04:58

    And you could also (foolishly) just use single-letters ("a" and "b" and "c") for all classes, variables, functions, and methods.

    But WHY would you want to?

    Use names that make sense, not:

    function a(a)
    {
        int a = a.a;
        return a
    }
    
    0 讨论(0)
  • 2020-11-29 05:01

    Case folding is only simple in English (and for all characters < 128). The German sz or "sharp s" (ß) doesn't have an upper case variant in the ISO 8859-1 charset. It only received one in Unicode after about a decade of discussion (and now, all fonts must be updated...). Kanji and Hiragana (Japanese alphabets) don't even know lower case.

    To avoid this mess, even in this age of Unicode, it is not wise to allow case folding and unicode identifiers.

    0 讨论(0)
  • 2020-11-29 05:01

    Many (non-programming) languages (e.g. European using the Roman alphabet) are case-sensitive, so it's natural for native speakers of those languages to use upper- / lower-case distinctions.

    The very idea that programming languages wouldn't be case-sensitive is a historical artifact arising from the limitations of early-generation hardware (including pre-computer teletype machines that used a 5-bit character code).

    People who argue for case-blind languages must be unable to distinguish

    IAmNowHere
    

    from

    IAmNowhere
    

    (It's a joke! ;-)

    0 讨论(0)
  • 2020-11-29 05:01

    From .NET Framework Developer's Guide Capitalization Conventions, Case-Sensitivity:

    The capitalization guidelines exist solely to make identifiers easier to read and recognize. Casing cannot be used as a means of avoiding name collisions between library elements.

    Do not assume that all programming languages are case-sensitive. They are not. Names cannot differ by case alone.

    0 讨论(0)
  • 2020-11-29 05:02

    It's actually extremely practical, both for the developer and for the language syntax specification: lower/upper case distinction adds a great deal of expressiveness to identifier naming.

    From the point of view of the language syntax, you can force certain identifiers to start with a lower or upper case (for instance Java class name). That makes parsing easier, and hence helps keeping the syntax clean.

    From a developer point of view, this allows for a vast number of convenient coding conventions, making your code clearer and easier to understand.

    0 讨论(0)
  • 2020-11-29 05:03

    Back when parsing and compiling was real expensive and would take all night it was advantageous to the compiler if it didn't have to worry about case.

    Once identifiers came in to existence that were only unique via their case it became very difficult to go back. Many developers liked it and there doesn't seem to be a big desire to undo it.

    0 讨论(0)
提交回复
热议问题