Case Sensitivity

This is a discussion on Case Sensitivity within the General Discussions forums, part of the Community Boards category; While looking for a case insensitive way to find files on Linux, I came across this post on Coding Horror. ...

Case Sensitivity

While looking for a case insensitive way to find files on Linux, I came across this post on Coding Horror. (It's an awfully old post in internet terms, but it sparked my interest.)

The author raises some points as to why case sensitivity is "a giant productivity time sink" and quite frankly I'm not seeing the merit in his argument. To me case-sensitivity seems like a great feature in that it enforces readability. It's easier to see that "Variable" is the same identifier as "Variable" than it is to compare "Variable" and "VARIable". That, and I always find myself doing stuff like this when I need a single instance of a class:

Code:

class Apple;
Apple apple;

In the comments, I saw the issue going to "how lenient should the language be, then?" If case insensitivity is OK, should the language forgive typos as well? Should "Varyable" == "Variable"? Obviously I hadn't gone as far as to consider this - I'm still saying case sensitivity is a good thing. But the idea of a compiler that forgives little errors like this is quite interesting.

Oddly enough, however, I'm all for case insensitivity in filesystems. And I love the program that comes up with suggestions when I make a typo on the linux terminal (though this is markedly different than assuming it knows what you meant to say). It might just be that I've had different experiences working with filenames, or that I haven't ever had a need to have two files differing only by case.

Which brings me to my point: do you guys have any reasons for favoring one or the other (case sensitivity vs insensitivity (vs typo-correction???))? And, do any of you have so-called "horror stories" regarding case sensitivity that are apparently so common?

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Clang can actually find and correct typos in your programs - but it won't actually generate code in such cases.

Case insensitivity is fine, although I disagree that sensitivity is a productivity sink. Just keep to a naming convention and there can be no question on how to write something. Instead of a compiler being case insensitive, I think IDEs should be case correcting. That is, if you type a variable with the wrong case, the IDE should just change it. No time lost, but the code remains absolutely clear.

As a general rule, though, a programming language cannot be sloppy. Case insensitivity isn't sloppy, it's just a consistent and simple equivalence rule for identifiers. The important property is that every equivalence class is closed. Typo correction does not have this property. Dog could be a typo for Hog could be a typo for Hag could be a typo for Hat could be a typo for Cat - where is the limit? (Also, Cog, Dot, Cot, Hot, and many other words pave the way for this little transformation.) An equivalence relation for variable names MUST be transitive, or your language becomes terribly ambiguous.

To me case-sensitivity seems like a great feature in that it enforces readability. It's easier to see that "Variable" is the same identifier as "Variable" than it is to compare "Variable" and "VARIable".

You could always enforce readability by having the editor force a case after the word is complete. Languages like Visual Basic will force whatever case you use at declaration on every instance of that identifier in the code. So if I declare "VARIable" and later on write "Variable" it will automatically be changed by the editor to reflect it's original case.

Of course, that still doesn't allow you to do this...

Originally Posted by bernt

That, and I always find myself doing stuff like this when I need a single instance of a class:

Code:

class Apple;
Apple apple;

...but then, I hate that. Even in a case-sensitive language that is barely considered acceptable practice. If being able to do it was the only argument for case-sensitivity then I'd be rallying against it tomorrow.

I totally agree case sensitivity is important and useful. It also much simplifies parsing. I recently wrote an HTTP server, and HTTP is case insensitive, which is a total pain. Totally horrible choice that was. Contra the coding horror guy, I'd say it is a drain on productivity, and I bet the amount of energy consumed inside the WWW everyday so that servers/browers can treat:

content-length
Content-Length
cOnTent-LENGTH

as equivalent is enough to power a small city. Honestly. People that think this kind of waste and inefficiency are worthwhile because it makes things more foolproof are...fools. If you are that incompetent and lazy, stay away from a keyboard. I'm sure, WRT the web, various standards are this way in order to "provide leniency" for sloppy work, and a consequence is that it encourages it. Awesome.

Originally Posted by bernt

That, and I always find myself doing stuff like this when I need a single instance of a class:

Code:

class Apple;
Apple apple;

I partially agree with SlyMaelstrom, ie, this almost seems like a bad practice, but I occasionally do it myself because it also seems intuitive. I guess context is important -- if it is short and sweet, why not?

I often (but not always) capitalize the first letter of a type, and (when I get to choose) always capitalize the first letter of a global, and never the first letter of a local variable.

All this demonstrates that literate human beings distinguish between upper and lower case. Why render it meaningless?

Oddly enough, however, I'm all for case insensitivity in filesystems.

Not me. File system hierarchies often form parts of projects so I regard those names exactly the same way I regard those of variables in code. I'm very against the legal inclusion of spaces in file names. Poor choice. If the OS wants to provide stuff like that to the end user, the filesystem should use meta-data for that purpose.

And I love the program that comes up with suggestions when I make a typo on the linux terminal

Instead of a compiler being case insensitive, I think IDEs should be case correcting. That is, if you type a variable with the wrong case, the IDE should just change it. No time lost, but the code remains absolutely clear.

This I can't agree. I don't look with good eyes at the notion of IDEs overruling anything I write. Especially if they do it silently. Besides if I'm allowed to easily ignore case sensitivity, there's a good chance I'll end up forgetting all about consistency.

I cannot imagine any good coming from an IDE that hides language features from me, instead of exposing them. Of course... this for anyone considering case-sensitivity a feature.

Originally Posted by MK27

I often (but not always) capitalize the first letter of a type, and (when I get to choose) always capitalize the first letter of a global, and never the first letter of a local variable.

Indeed. Very powerful use of this language feature. And why I'm actually a fan of case-sensitivity in general-purpose programming languages.