Question:
programming: how do you do the casing of your variable names?
a
2010-03-08 18:36:32 UTC
one thing i absolutely hate about most programmers is the way they case their variables. for example why do people go all like "nextRole" or "currentEmployee"? what is the ####ing point with using lowercase for the first word and then proper casing for the rest? additionally, what if your variable name consists of just one word? who wants to use a whole variable name in all lowercase? personally, i like proper camel casing, so it would be like "NextRole" or "CurrentEmployee". seriously, convince me why lowercasing the first word is not completely retarded.

i actually started coding like that in my early days. the only reason why is bcuz i followed other programmers' examples and just adopted it bcuz everyone else was doing it and, hey, what did i know? then one day i asked myself, "what is the point?" as soon as i realized there was no logical answer, i immediately tossed that pointless casing convention out the window and began using proper casing.

i hate it so much, in fact, that when i see code written by other members on my team, i actually rewrite it so that all variables in the entire file are properly cased. i hate to sound like a d!ck here, but i wouldn't be so aggressive about this if there were some rhyme or reason to it. and don't go spouting off about personal preference. what.. you personally prefer to say "thisVariable" vs "ThisVariable" for what reason exactly? ok then.. i personally prefer "THISvariable" or "THiSVaRiaBLE". why? BCUZ I AM A NOOB PROGRAMMER AND IT'S WHAT I PREFER.

imo, proper casing is just more consistent. there's no reason to case your variable names any other way. yes, you agree with me and plan on changing your casing convention over to mine as soon as you finish reading this last sentence.
Five answers:
FlagMichael
2010-03-08 18:43:37 UTC
I think it is a holdover from Hungarian notation. In that style, variable names began with a three or four abbreviation for the variable type, like intFubar, and the abbreviation was not capitalized.



I'm with you - proper case is good for descriptive variable names like CustomerName. Conventions come from popular usage, so let's do what we think best.
Ratchetr
2010-03-08 18:55:31 UTC
Consistency between team members is more important than your personal preferences. Leave your religion at the doorstep. (And this is a religious issue...meaning there really isn't a logically right or wrong god to pray to here.)



The standard we use at work is lower case first letter for variable names, upper case first letter for method and property names. _name for private class variables. It works reasonably well. The _ and lower vs. upper first character provide a very localized visual clue about what type of variable I'm looking at. Knowing that _foo is a private member, foo is a local variable and Foo is a property without having to backtrack to the definition makes it easier to suss out what a piece of code is doing at first glance.



If you're rewriting other peoples code just to change the case of a variable, then, yes, you are a d!ck. I would fire you for that after the 2'nd or 3'rd warning. The last thing I want to see when I diff different versions of code is a crapload of lines with meaningless changes. And sooner or later, you'll goof and introduce a bug with your rewrites.



Why should I pay you to rewrite code that isn't broken, clutter up the source control system, and introduce bugs in working code? I can hire an offshore developer to do that at 1/10'th your salary.
Michael
2010-03-08 18:43:29 UTC
A proper naming for your variable is to put the data type of the variable in front of the name for example: intAge, or strName



This helps with your programming and others to understand what this data type this variable is.

Some programmers just use a 'v' infront to mean that this is a variable like this: vAge, vName



These naming convention is very helpful to a programmer as in some cases (visual programming language like Vb.Net) you can drop controls and change their name/ID. This will help to differentiate controls form variable.



There is no reason to casing the variables name as you have mentioned. You can case anyway you want, just personal preference.
anonymous
2010-03-08 18:51:33 UTC
For proper naming convention, variables must start with a lowercase letter... if the variable name is composed of 2 words, then the second word should begin with an uppercase. For example, customerName....

Classes are the ones that should begin with a capital letter.. For example

class Customer
The Phlebob
2010-03-08 18:47:54 UTC
If you're programming on your own, you can use any case you darn please, but if you wind up programming for an organization, they're likely to take a dim view of your code, no matter how great you think it is, if you don't follow their coding conventions. The truth is that in an organization of any size, others are going to have to someday maintain your code. Being able to read your code and understand it quickly will be important to their doing their jobs well. Having to wade through code with weird casing will slow them down.



Hope that helps.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...