Question

Just wondering why people like case sensitivity in a programming language? I'm not trying to start a flame war just curious thats all.
Personally I have never really liked it because I find my productivity goes down when ever I have tried a language that has case sensitivity, mind you I am slowly warming up/getting used to it now that I'm using C# and F# alot more then I used to.

So why do you like it?

Cheers

Was it helpful?

Solution

Consistency. Code is more difficult to read if "foo", "Foo", "fOO", and "fOo" are considered to be identical.

SOME PEOPLE WOULD WRITE EVERYTHING IN ALL CAPS, MAKING EVERYTHING LESS READABLE.

Case sensitivity makes it easy to use the "same name" in different ways, according to a capitalization convention, e.g.,

Foo foo = ...  // "Foo" is a type, "foo" is a variable with that type

OTHER TIPS

An advantage of VB.NET is that although it is not case-sensitive, the IDE automatically re-formats everything to the "official" case for an identifier you are using - so it's easy to be consistent, easy to read.

Disadvantage is that I hate VB-style syntax, and much prefer C-style operators, punctuation and syntax.

In C# I find I'm always hitting Ctrl-Space to save having to use the proper type.

Just because you can name things which only differ by case doesn't mean it's a good idea, because it can lead to misunderstandings if a lot of that leaks out to larger scopes, so I recommend steering clear of it at the application or subsystem-level, but allowing it only internally to a function or method or class.

Case sensitivity doesn't enforce coding styles or consistency. If you pascal case a constant, the compiler won't complain. It'll just force you to type it in using pascal case every time you use it. I personally find it irritating to have to try and distinguish between two items which only differ in case. It is easy to do in a short block of code, but very difficult to keep straight in a very large block of code. Also notice that the only way people can actually use case sensitivity without going nuts is if they all rigidly follow the same naming conventions. It is the naming convention which added the value, not the case sensitivity.

I maintain an internal compiler for my company, and am tempted to make it a hybrid - you can use whatever case you want for an identifier, and you have to refer to it with the same casing, but naming something else with the same name and different case will cause an error.

Dim abc = 1
Dim y = Abc - 1 ' error, case doesn't match "abc"
Dim ABC = False ' error, can't redeclare variable "abc"

It's currently case-insensitive, so I could probably fix the few existing errors and nobody would complain too much...

Many people who like case-sensitivity misunderstand what case-insensitivity means.

VB .NET is case-insensitive. That doesn't mean that you can declare a variable as abc, then later refer to it as ABC, Abc, and aBc. It means that if you type it as any of those others, the IDE will automatically change it to the correct form.

Case-insensitivity means you can type

dim a as string

and VS will automatically change it to the correctly-cased

Dim a As String

In practice, this means you almost never have to hit the Shift key, because you can type in all lowercase and let the IDE correct for you.

But C# is not so bad about this as it used to be. Intellisense in C# is much more aggressive than it was in VS 2002 and 2003, so that the keystroke count falls quite a bit.

I believe it enforces consistency, which improves the readability of code, and lets your eye parse out the pieces better.

class Doohickey {

  public void doSomethingWith(string things) {
     print(things);
  }
}

Using casing conventions makes that code appear very standarized to any programmer. You can pick out classes, types, methods easily. It would be much harder to do if anyone could capitalize it in any way:

Class DOOHICKEY {
  Public Void dosomethingwith(string Things) {
    Print(things);
  }
} 

Not to say that people would write ugly code, but much in the way capitalization and punctuation rules make writing easier to read, case sensitivity or casing standards make code easier to read.

I believe it is important that you understand the difference between what case sensitivity is and what readability is to properly answer this. While having different casing strategies is useful, you can have them within a language that isn't case sensitive.

For example foo can be used for a variable and FOO as a constant in both java and VB. There is the minor difference that VB will allow you to type fOo later on, but this is mostly a matter of readability and hopefully is fixed by some form of code completion.

What can be extremely useful is when you want to have instances of your objects. If you use a consistent naming convention it can become very easy to see where your objects come from.

For example: FooBar fooBar = new FooBar();

When only one object of a type is needed, readability is significantly increased as it is immediately apparent what the object is. When multiple instances are needed, you will obviously have to choose new (hopefully meaningful names), but in small code sections it makes a lot of sense to use the Class name with a lowercase first character rather than a system like myFooBar, x, or some other arbitrary value that you'll forget what it does.

Of course all of this is a matter of context, however in this context I'd say 9 times out of 10 it pays off.

There's a lot of answers here, but I'm surprised no one pointed out the obvious example that also makes fun of a stackoverflow competitor:

expertSexChange != expertsExchange

Case is very important when you use camel case variable names.

It gives you more options.

Bell bell BEll

are all different.

Besides, it drives the newbies that were just hired nuts trying to find out why the totals aren't coming out right ;o)))

Because now you actually have to type everything in a consistent way. And then things suddenly begin to make sense.

If you have a decent editor - one that features IntelliSense or the same thing by another name - you shouldn't have any problems figuring out case-sensitive namees.

Case sensitivity is madness! What sort of insane coder would use variables named foo, foO, fOo, and fOO all in the same scope? You'll never convince me that there is a reason for case sensitivity!

I think there is also an issue of psychology involved here. We are programmers, we distinguish minutely between things. 'a' is not the same ASCII value as 'A', and I would feel odd when my compiler considers them the same. This is why, when I type

(list 'a 'b 'c)

in LISP (in the REPL), and it responds with

(A B C)

my mind immediately exclaims 'That's not what I said!'. When things are not the same, they are different and must be considered so...

I usually spend some time with Delphi programming on vacation, and most of the other time I use only C++ and MASM. And one thing's odd: when I'm on Delphi, I don't like case sensitivity, but when I'm on C++ - I do. I like case sensitivity, becouse it makes similar words (functions, variables) look similar, and I like non-case sensitivity because it doesn't put excessive restrictions on syntaxis.

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.

It's useful for distinguishing between types in code.

For example in Java: If it begins with a capital letter, then its probably a class. if its ALL_CAPS its probably a constant.

It gives more versatility.

Feels like a more professional way of coding. Shouldn't need the compiler to figure out what you meant.

I felt the same way as you a long time ago when i used VB3/4 a lot more. Now I work in mainly C#. But now I find the IDE's do a great job of finding the symbols, and giving good intellisense on the different cases. It also gives me more flexibility in my own code as I can have differnt meaning to items with different cases, which I do a lot now.

Also a good habit if your working in Linux where referencing file names is case sensitive. I had to port a Windows ColdFusion application to work in Linux and it was an utter nightmare. Also some databases have case sensitivity turned on, imagine the joy there.

It is good habit though regardless of platform and certainly leads to a more consistent development style.

IMHO it's entirely a question of habit. Whichever one you're used to will seem natural and right.

You can come up with plenty of justifications as to why it's good or bad, but none of them hold much water. Eg:

  • You get more possible identifiers, eg. foo vs Foo vs FOO.
  • But having identifiers that differ only in case is not a good idea
  • You can encode type-info into a name (eg. FooBar=typename, fooBar=function, foo_bar=variable, FOO_BAR=macro)
  • But you can do that anyway with Hungarian notation

Because it's how natural language works, too.

In progamming there's something to be said for case sensitivity, for instance having a public property Foo and a corresponding private/protected field foo. With IntelliSense it's not very hard not to make mistakes.

However in an OS, case sensitivity is just crazy. I really don't want to have a file Foo and foo and fOO in the same directory. This drives me cray everytime i'm doing *nix stuff.

For me case sensitivity is just a play on scopes like thisValue for an argument and ThisValue for a public property or function.

More than often you need to use the same variable name (as it represents the same thing) in different scopes and case sensitivity helps you doing this without resorting to prefixes.

Whew, at least we are no longer using Hungarian notation.

After working many years with legacy VBScript ASP code, when we moved to .NET we chose C#, and one of the main reasons was case sensitivity. The old code was unreadable because people didn't follow any convention: code was an unreadable mess (well, poor VBScript IDEs helped on that).

In C# we can define naming conventions and everybody must follow them. If something is not correctly cased, you can rename it (with refactoring, but that's an IDE feature) and there won't be any problem because the class or variable will be named the same way all across the code.

Finally, I think is much more readable if everything is correctly cased. Maybe is faster to write without case sensitivity, but from a code reviewing and maintaining point is not the best thing because skipping through the code looking for something is easier. For example is easier to find all the 'foo' strings in a glance than looking for 'foo', 'Foo', 'FOO', 'FOo'...

Case-insensitive languages don't easily generalize to non-ASCII character sets. Proper case conversion for a language other than English is not a straightforward task, and depends on system locale, among other things.

Case insensitivity is very difficult, unless you restrict the syntax to ascii (or only apply the case insensitivity to the ascii characters), and also you need to restrict the locale.

The rules for determining upper and lower case of characters is neither well defined, nor is it lossless.

Some characters can have more than one 'lowercase' form. Some people will disagree as to what the correct uppercase form should be.

(Some languages and environments allow for almost character to be used in names)

Consider In C# what is the difference between ToUpper() and ToUpperInvariant()?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top