Why are many languages case sensitive?

后端 未结 30 1956
执念已碎
执念已碎 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 05:13

    Because people seriously overthink things.

    Case insensitivity works best when it's also case-preserving and combined with a separation between type and variable namespaces. This means that:

    • If you declare a class as 'TextureImage' and then try to use it as 'textureImage', the IDE can autocorrect you. This gives you the advantage that you'll never have to hit the shift key unless you're declaring an identifier or using an underscore.

    • Just like in Java and several other languages; it's perfectly valid to type "MyClass myClass". The IDE and the compiler should have no problem differentiating between the use of a type and the use of a variable.

    In addition, case insensitivity guarantees that 'o' and 'O' will never refer to different objects. Common arguments include:

    • "sOmEoNe wIlL tYpE cOdE lIkE tHiS"; => and that someone will _never_ be allowed to join a programming team, so this is a strawman argument. even if they did manage to do so, case insensitivity is more the solution than the problem, because it means that you don't have to remember whatever crazy uppercase/lowercase combination they use.

    • "you can't internationalize case insensitivity easily!"; => over 95% of programming languages are written in english for a very good reason. there are no competing character encodings and the vast majority of keyboards on earth are english based (in partial or whole). supporting unicode identifiers is perhaps the dumbest idea anyone has came up with in the 21st century; because a good portion of unicode characters are frikkin invisible surragates, reading code is hard enough without having to use google translate, and writing code is hard enough without having to copy-paste identifiers or use a character map.

    • "but case sensitive languages have more identifiers!"; => no, they have grammatically overloaded identifiers, which is substantially worse.

    I don't use any case-insensitive languages, but the advantages are blatantly obvious if you think about this sort of thing seriously.

提交回复
热议问题