Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case sensitive Vs insensitive syntax

Can anyone make really a good case ( :-) ) for being case sensitive?

C#: case sensitive VB.NET: not case sensitive C++: case sensitive ...

Worse part: XML which is used inside a language like VB.NET is case sensitive.

I was making the case that it is ridiculous and can only cause harm after we found a bug in our system due to the fact that XML had both Value and value nodes...

I am asked over and over in comments

"Perhaps you can come up with a single argument for why case insensitive is the right choice in such a world?"

Here is an example: I see it analogous to the issue of: URL's should be case sensitive? www.cnn.com <> Www.cNN.com ? Of course they should be the same, ID theft heaven! because humans don't put that much attention to 2 strings that are the same but might have otherwise different casing. Programmers are humans. So getAge() and getage() are the same in most human's minds.


Please notice: I do not think we want the code to actually have a function defined as getAget() and then have code calling it getage(), VS (vb.net) will automatically correct getaget to getAge. So the code is clear and the programmer is aware of the correct capitalization. My point is: good IDE makes the issue non relevant, but it works better in a non case-sesnsetive language like vb.net then lets say c#. Reference: here

like image 581
csmba Avatar asked May 21 '09 22:05

csmba


4 Answers

Case rules depend on culture. Do you want a programming language where a variable i is sometimes considered to be the same as one called I and sometimes they're different variables? (That's not a made-up example, btw. In Turkish, I is not an upper-case i.

Honestly, it's pretty simple. Do you want the compiler to correct you when you make a typo, or do you want it to guess at what you meant? The latter leads to bugs, as you found out. VB assumes "oh, you probably meant the same thing, that's ok, we won't stop you", and XML took you literally.

Your bug didn't occur because case sensitivity is bad, it occurred because being sloppy is bad. Arbitrarily changing case may, at best, cause no problems, and at worst it will cause errors. Assume the worst, and be consistent with your case. Which, incidentally, is what case sensitive languages force you to do. Whether or not your tools are case sensitive, the programmer should be case sensitive. Being case sensitive saves you a lot of trouble as long as the world features insensitive as well as sensitive tools. If we could remake the world so that everything was case insensitive, a lot of the reasons in favor of sensitivity would go away. but we can't.

A little side note of course: In many languages, it is common to give variables and types the same names, but with different capitalization:

Foo foo; // declare a variable foo of type Foo

Of course you could argue that "you shouldn't do that", but it's convenient, and it immediately tells the reader what type the variable has. It allows us to create a Log class, and a log object. And since the purpose of this object is to log, the name is kinda obvious.

And a final point to consider:

Case matters in real languages. A word that begins with upper-case is different from the same one but with leading lower-case. The word "worD" is not correct english. Information is encoded in the case, which makes text easier to read. It tells us when we encounter a name, for example, or when a sentence begins, which is handy. Allowing people to ignore case rules makes text harder to read. And since code should generally be written as readable as possible, why shouldn't we do the same in programming? Allow the case to encode important information. In many languages, Foo is a type, and foo is a variable. That's important information. I want to know this when I program. If I see a function called "Getage", I wonder if that's some English word I've never heard before. But when I see "GetAge", I immediately know that it should be read as the word "Get" followed by the word "Age".

By the way, here's a nice example of the fun surprises you can run into in case sensitive languages.

like image 132
jalf Avatar answered Nov 18 '22 12:11

jalf


Slop is never a good idea in a programming language. You want things to be as specific as possible. You never want your language to guess at anything and it should allow as few ways to solve a given problem as possible.

As for a specific answer, how about readability? Doesn't stoRetroData visually differ quite a bit from storeTRodAtA? Not that anyone would do such a thing, but what's the point in allowing it?

I can't come up with any reason to allow ignoring case.

At least that's my opinion--but your mileage may vary.

Edit: I probably should have started this out with a disclaimer:

I learned to program in basic and had this same thought fleetingly about 18 years ago. Trust me, it's one of those things you'll look back on in 20 years and go "Oh, yeah, I was pretty wrong about that" (as I am right now)

like image 43
Bill K Avatar answered Nov 18 '22 12:11

Bill K


  1. History It is the way it has been done. The XML is VB.NET is case sensitive because the XML standard requires it
  2. Internationalization Are we going to support case in all languages (French, Japanese, Hebrew, Klingon, etc.)?
like image 2
jrcs3 Avatar answered Nov 18 '22 12:11

jrcs3


Several case sensitive languages nowadays are that way because the languages they were based on were case sensitive and the transition would be easier. Personally I prefer case sensitive, but Jeff Atwood wrote a pretty good article on why case sensitivity may no longer be necessary.

like image 2
Brandon Avatar answered Nov 18 '22 14:11

Brandon