views:

982

answers:

22

Hi all,

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

+1  A: 

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)))

Keng
Yeah, but using identifiers that differ only in case is really awful programming practice.
oh, absolutely! I wouldn't do it myself. It makes it murder to support; the new-hire thing was really more tongue in cheek. however, when you're working in a really terse environment like MUMPS, it's really important to be able to have that flexibility.
Keng
If you're working with MUMPS, case-sensitivity is the least of your problems.
Adam Lassek
+1 for humor ()
RCIX
A: 

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.

BlueVoid
Not sure if this is a valid answer. If Java was case insensitive, you could still do declare variables however you want, you just couldn't have 'COUNTER' and 'counter' in the same scope because they would be the same variable.
Outlaw Programmer
@Outlaw Programmer Well, there are "naming conventions" for that and that's exactly what sensitivity enforces.
Marc Climent
A: 

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

RedWolves
+25  A: 

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
Kristopher Johnson
I often find myself using _foo, foo and Foo all in the same 10 lines, expecially in C# with constructors and properties.
Matthew Scharley
Not everyone would consider "Foo foo = FOO;" to be a feature.
Which is why there is a need for the upcoming infered types... (can't remember the C# syntax, in D it goes:auto foo = new Foo(); //<-- why do you need to write Foo twice?
xan
@xan, they're not upcoming, they're in C#3. var foo = new Foo();
Wedge
@xan: Inferred types are completely irrelevant to this discussion. But since you mention it, replacing a three-letter identifier with a four-letter one in order to make the code *less* explicit does not look like a win to me.
You don't need case sensitivity for that. I often write "Dim Foo as new Foo" in VB.
Jonathan Allen
Since I switched more-or-less permanently from VB to C#, case-insensitivity is the one thing I miss. As others have said here, you're -usually- making yourself more prone to errors if you're only distinguishing identifiers by a single difference in case.
AR
You've just described the very reason I don't like case-sensitivity. Humans are natural language interpreters, not ASCII parsers. Overloading the function of a signifier by changing its case can be easily misinterpreted by our faulty brains and lead to more error prone code.
TrickyNixon
@Mike F, it's not less explicit, it's less redundant. var foo = new Foo(); is not ambiguous in the least.
Adam Lassek
@TrickyNixon -- excellent point.
Tom A
@TickyNixon I invite you to review our old ASP VBScript code. After that, your opinion on case sensitivity may change a lot. This feature enforces conventions which is always good IMHO.
Marc Climent
+1  A: 

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.

Justice
A: 

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.

mattlant
A: 

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
A: 

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.

Adam
+2  A: 

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.

Bryan M.
Casing conventions and case sensitivity are different.While I agree with casing conventions, there is no reason why C# couldn't be smart enough to change the case of identifiers like VB does.
Jonathan Allen
+5  A: 

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.

Joe Brinkman
+6  A: 

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.

Cade Roux
If you build a system that allows even an idiot to code, you will get a lot of idiots coding. VB is just such a system. The problem is that while they can all stick widgets to forms they cannot FINISH the job, and this is often not discovered until probation is over.
Peter Wone
The versions of VB I've used would sometimes choose to change the case of all the other instances in your code to match the one you've just typed, instead of changing the one you've just typed to match the rest which would seem more logical. I don't know whether they've fixed this in later versions.
Mark Baker
Yes, the universal recasing has been fixed since VB 7 (.NET 1.0).
Jonathan Allen
Even pre VB.NET, it would use the last version. I don't miss VB in any way, but I almost wish the C# IDE would put me in the right case immediately without having to Ctrl-Space - in the old C days I didn't have to use a million different frameworks that I can't keep all in my head.Love Intellisense
Cade Roux
+1  A: 

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!

raven
No one would, of course. However, with case sensitivity, you can easily distinguish the difference between the 'foo' variable and the 'Foo' class, and use them both in the same scope (Foo foo = new Foo())
Fortega
+3  A: 

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...

Jacob
This is a good idea but might be annoying without IDE support.
Dan Goldstein
+2  A: 

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.

+1  A: 

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...

sundar
+3  A: 

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.

Kyralessa
That assumes you're using an IDE though. :)
Jason Baker
True. If you're a hard-core Notepad VB .NET developer, you have a right to be upset about how this works. :)
Kyralessa
if you're a .NET developer using notepad, you need to be locked up in a nice padded room.
gbjbaanb
Actually, VB is "case correcting", not "case insensitive".
Tom A
Actually, it's both. You can put in the keywords in all caps or all lowercase and VB .NET will build and run just fine. I'm hard-pressed to think of any instance where case makes a difference in VB .NET. By the way, see here for an interesting sample of what VB .NET would look like with all lowercase keywords: http://www.panopticoncentral.net/archive/2007/07/20/21212.aspx
Kyralessa
Much better, though still a little verbose for me. Reminds me of Lua.
RCIX
+1  A: 

Because it's how natural language works, too.

Andy Lester
I have to disagree. Speak a sentence, any sentence. The capitalization is purely by convention (ok, ok... RULES of grammar). In natural language, it's the word that matters, not how it's capitalized.
AR
Natural language is NOT case-sensitive.
Yarik
YeS IT iS! THiS LoOk RIghT? in FACt, FiREfoX iS CoMPLaInING aboUT EvERY WOrd EXCepT ONE or tWo...
RCIX
A: 

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.

Rik
A: 

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.

rshimoda
+1  A: 

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.

akalenuk
+1  A: 

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.

Tom A
A: 

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'...

Marc Climent