Feeling Sensitive About Case in C#

I have no idea why variable names in C# were made case-sensitive. As a VB guy trying to get into C#, it seems stupid that anyone would want one variable called strMyVar and another called strmyVar. The really annoying part is that when I want to re-assign a value to a declared variable, I have to look for the declaration version, copy it, and paste it where I need it so I get the case correct. In VB, I usually remember the variable name but not the case, so I can just type strmyvar and let the VS.NET editor fix up the case.

Anyway, this rant does have a purpose: to request a two-part Visual Studio feature or add-in. First, it would have a mode that would forbid declaration of an identical variable name in that scope no matter what the case. Second, once a variable is declared, the tool would fix up any form of it - just like the way VB does.

The sniggering, pseudo-macho types who believe that "real developers thrive on case-sensitivity" wouldn't have to use the wimp-case option. They could still feel very superior - while taking longer to get their work done.

Oh, and don't get me started on why the C# editor waits for me to recompile before it discovers that I've already fixed stuff it was complaining about.

Ken
MVP [ASP.NET]

 

15 Comments

  • Case sensitivity is a must-have for most C-based developers. For example, if you have a class named Order, you're probably going to call its instantiation order. That lets you do things like:



    foreach (Order order in orders)

    {}



    I always have a hard time following VB code because the instantiation names have to be different from the type names themselves.



    This is also why Microsoft doesn't recommend C# to VB devs.

  • Dude, i feel your pain, and you have my sympathies.



    Ed: Just because you _can_ do things like

    foreach(Order order in orders)



    doesn't mean you should. This just looks ugly :)

  • As with VB.NET, if you use Visual Studio, or the express versions, Intellisense, can help you with casing. And I can't speak for others, but I don't overlap variable names by case only, but it is a nice feature.



    And take note that Intellisense in VB.NET does keep casing consistent. So even though it doesn't really matter, it's still good style to keep the casing the same. <grin>

  • Hey Ken,

    I've been pushing the background-compilation thing for a while now... Cyrus and Jaybaz will respond "that's the way we want to go" but we probably won't see it any time soon :(

  • It is stupid that anyone would use strMyVar and another called strmyVar, but that is not why I and other C# developers prefer case-sensitivity.



    The differences in casing occur in the very first character.



    Lowercase initial character signifies variables, either private or local.

    Uppercase initial character signifies

    functions, or public properties.



    There are many of us from the C/C++/Java/C# world who feel just as strongly against the case-insensitivity of Visual Basic.

  • It is C language Tradiction.

  • +1 for an option for C# case sensitivity fixer upper



    +1 for the ability to turn background compilation on OR off (I would love to turn it off in VB from time to time, so sloooow)

  • Every time this comes up, I try to move this discussion off of personal preference or tradition. The C# designers dumped a lot of bad traditions from C. They chose not to dump this one. It really comes down to the differing worldviews of the VB folks and the C/++/#/Java folks. The C world view is that the computer is the reality. For the computer, the idea that "It" and "it" could ever be the same (or even related to each other) is ludicrous. For humans on the other hand, the connection between the two is obvious. The VB world view is that programmer is the reality and the computer is there to carry out our wishes. If the compiler enforced the connection between Order and order, then I would be all for case sensitivity. Until then, case sensitivity is nothing more than a flexibility that can be the source of bugs. If you program in C#, you should avoid variables that differ only in case.

  • case sensitivity in c# is rediculous, just like adding a ";" at the end of every line just so you don't have to add anything the other 2% of the time is just as rediculous.



    plain brilliant!

  • The language we use to communicate is based on the difference between upper and lower case so for me it is natural with case-sensitivity.



    I have always disliked Windows/DOS for their use of case-insensitivity. It feels plain wrong.

  • (yes, I'm feeling quite sensitive--it's a major annoyance!!) It's called a user option, if necessary. You provide a friggin checkbox in the options that says "Intellisense is case-insensitive". If checked, use a text test rather than a binary one. I can guarantee you that, just like intellisense itself--which hard core coders HATED at first and then started liking and then couldn't do without--99% of the people will have it it use, at least eventually.



    p.s. Oh, was that you writing Snarf? You totally misspelled your name--I saw 'snarf', but didn't recognize it.

  • oNlY sUpErIoR sEe lAnGuAgE dEvElOpErS cAn fAtHoLm wHy cAsE iS iMpOrTaNt yOu vB tWitS

    tHiS iS aLsO wHy mIcRoSoFt dOeSn’T rEcOmMeNd sEe sHaRp tO vB dEvS !!

    Goddamm Mr. Ed could you be any more full of yourself?

    I work in both vb and c# and they both have features I like and don't like. Really though the whole curly braces thing is soooooo 1980.

  • I really don't understand why people are still using VB at all.

  • While most of my recent work has been in C# I am still a fan of VB as well. And no matter what you think about C# everything it can do can be done in VB... Kinda the whole point behind CLR.

  • VB cannot do everything that C# can do. Read "CLR via C#" from MS Press for details.

Comments have been disabled for this content.