What's the benefit of case-sensitivity in a program language?

1.5k Views Asked by At

Possible Duplicate:
Is there any advantage of being a case-sensitive programming language?

My first programming experiences where with the Basic family (MSX Basix, Q-basic, VB). These are all not case-sensitive. Now, it might be because of these first experiences, but I've never grasped the benefit of a language being case sensitive. On the contrary, I think it is a source of unneeded overhead and bugs, and it still annoys me when I use e.g. Java or C.

Now, I just read on Clojure (a Lisp-dialect) and noticed - to my surprise - that one of the differences with Lisp is case-sensitivity.

So: what is actually the benefit (to the programmer) of having a case-sensitive language?

The only things I can think of are:

  • double the number of symbols
  • visual feedback and easier reading for complex variables using techniques like CamelCase, e.g. HopCount

However, the first argument doesn't hold because of being a major source for bugs (bad practice to use hopcount and HopCount in one method).

The second argument doesn't hold either, as a decent IDE can provide this also in an other way. A good example is the VBA IDE, which has a very good approach: the langauge is case-insensitive but as soon as you type a variable it will change it to the case used in its definition. For example, if you defined Dim thisIsMyVariable as string, it will change any occurrence of thisismyvariable into thisIsMyVariable). That provides the programmer with an immediate clue that the variable was actually typed-in correctly (because it changed appearance).

Edit: added ... benefit to the programmer ...

2

There are 2 best solutions below

2
On

Many naming conventions demand that symbols denoting objects from different semantic classes (types, functions, variables) have their own name casing rules. In Java, for example, types names always begin with a upper case letter, while variables, member function names etc. begin with a lower case letter. This effectively puts type names in a different namespace and gives a visual clue what a statement actually means.

// declare and initialize a new Point
Point point=new Point();
// calls a static member function of type Point
Point.fooBar();
// calls a member function of Point
point.moveTo(x,y);
0
On

One point is, like you said, visual aid. Most programming languages (and even frameworks) have conventions on how to capitalize variables, names, etc. Also, it enforces using uniform names everywhere, so you don't have a mess with the same variable referred to as "var", "Var" or even "VaR".

I can't remember of ever having bugs related to capitalization, so that point seems kind of contrived to me. Using 2 variables of the same name but different capitalization to me sounds like a conscious attempt to shoot yourself in the foot. Different capitalization conventions almost everywhere signify objects of completely different type (classes, variables, methods and so on), so it's pretty hard to make such a mistake due to the completely different semantics.

I'd like to think of it in this way: what do we gain by NOT having case-sensitivity? We introduce ambiguity, we encourage sloppiness and poor style.

This is a slightly subjective matter of course.