Click here to Skip to main content
16,006,594 members

Survey Results

Coding style: How do you name your local variables?   [Edit]

Survey period: 3 Apr 2006 to 9 Apr 2006

What's your convention de jour for your locals?

OptionVotes% 
Pascal Cased17110.56
camel Cased70243.36
Fixed letter prefix (eg lLocal)815.00
Hungarian prefix (eg strLocal)48229.77
Scope prefix (eg l_Local)362.22
Scope and Hungarian prefix (eg l_strLocal)1257.72

View optional text answers (100 answers)


 
GeneralRe: Why camelCased? Pin
QuiJohn3-Apr-06 5:59
QuiJohn3-Apr-06 5:59 
GeneralRe: Why camelCased? Pin
Ryan Roberts3-Apr-06 6:41
Ryan Roberts3-Apr-06 6:41 
GeneralRe: Why camelCased? Pin
QuiJohn3-Apr-06 6:48
QuiJohn3-Apr-06 6:48 
GeneralRe: Why camelCased? Pin
worldspawn3-Apr-06 20:59
worldspawn3-Apr-06 20:59 
GeneralRe: Why camelCased? Pin
Karl Josefsson3-Apr-06 23:09
Karl Josefsson3-Apr-06 23:09 
GeneralRe: Why camelCased? Pin
worldspawn4-Apr-06 13:41
worldspawn4-Apr-06 13:41 
GeneralRe: Why camelCased? Pin
Karl Josefsson5-Apr-06 5:33
Karl Josefsson5-Apr-06 5:33 
GeneralRe: Why camelCased? Pin
tec-goblin3-Apr-06 23:54
tec-goblin3-Apr-06 23:54 
Apart from some offensive-language details, I can sign this post.
Hungarian notation can die, because the way something is used and the UI can tell you exactly the type of a variable. I used it until recently for UI controls, but now I've changed txtxxxx to something like
xxxTextBox - and this because i can have a xxx variable and a xxx text box at the same time.
In this way autocomplete works waaay better, when I write xx I have already the 1-3 things related to the task at hand (I am occupied with xxx and I know it) and not ALL the text boxes of the class (:S). Yes, I know this notation is longer, but, well, I write the whole variable name exactly once, the other times autocomplete does it for me. My advice: learn to live with autocomplete.
Combining pascal and camel notation to distinguish between Properties and private variables works quite nice: the client sees consistently MyObject.Something when he wants to use a variable, and in your code you almost always write something for variables and Something for functions. It is very easy to get used to and you can understand very well what's happening. In the rare case that you accidentally write Something for a local variable, the compiler will easily optimize it. You haven't really done something wrong, just in some cases added some extra validity checks (sometimes you want to do it). So no harm can be done here.
Distinguishing between local variables and class variables has no good use IMO. A function has to be short, its variable declarations close to its use and it will be evident what's local and what's not (and most of the time, it just doesn't matter). Even if not, the variables will have good names. In the rare case that the names are not enough, write /// (in C#) comments over them and when you point the mouse over them, everything's clear. You should NEVER have to backtrack to the top of the file to see the variable declaration to understand what happens in a well written code.

So, to sum up: use camel notation and clear, evident names. Use camel notation to have all the useful information in the first letters of the variable. Autocomplete is your friend. The result will be a code easy to be read. If you have to correct someone's code which is not as clear the solution is to learn him to write evident names and not to use a convention that will slow down his productivity (hungarian notation=more keystrokes every time a variable is used which is always worst than more keystrokes only in the variable's declaration).

-- modified at 5:56 Tuesday 4th April, 2006
GeneralRe: Why camelCased? Pin
Kevin McFarlane3-Apr-06 10:12
Kevin McFarlane3-Apr-06 10:12 
GeneralRe: Why camelCased? Pin
Zoltan Balazs4-Apr-06 4:41
Zoltan Balazs4-Apr-06 4:41 
GeneralRe: Why camelCased? Pin
Hugo Vale4-Apr-06 5:05
Hugo Vale4-Apr-06 5:05 
GeneralRe: Why camelCased? Pin
Blake Miller4-Apr-06 6:13
Blake Miller4-Apr-06 6:13 
GeneralRe: Why camelCased? Pin
Ryan Roberts5-Apr-06 0:34
Ryan Roberts5-Apr-06 0:34 
GeneralRe: Why camelCased? Pin
Karl Josefsson5-Apr-06 5:42
Karl Josefsson5-Apr-06 5:42 
GeneralRe: Why camelCased? Pin
Leslie Sanford4-Apr-06 9:35
Leslie Sanford4-Apr-06 9:35 
GeneralRe: Why camelCased? Pin
Ryan Roberts5-Apr-06 0:31
Ryan Roberts5-Apr-06 0:31 
GeneralRe: Why camelCased? Pin
Todd Smith6-Apr-06 9:15
Todd Smith6-Apr-06 9:15 
GeneralRe: Why camelCased? Pin
Kevin McFarlane3-Apr-06 10:10
Kevin McFarlane3-Apr-06 10:10 
GeneralRe: Why camelCased? Pin
worldspawn3-Apr-06 21:01
worldspawn3-Apr-06 21:01 
GeneralK&R Pin
Nemanja Trifunovic3-Apr-06 1:50
Nemanja Trifunovic3-Apr-06 1:50 
GeneralRe: K&R Pin
Rob Caldecott3-Apr-06 2:46
Rob Caldecott3-Apr-06 2:46 
GeneralRe: K&R Pin
Nemanja Trifunovic3-Apr-06 3:14
Nemanja Trifunovic3-Apr-06 3:14 
GeneralRe: K&R Pin
Rohit Wason3-Apr-06 10:02
Rohit Wason3-Apr-06 10:02 
GeneralRe: K&R Pin
Kevin McFarlane3-Apr-06 10:15
Kevin McFarlane3-Apr-06 10:15 
GeneralRe: K&R Pin
Kevin McFarlane3-Apr-06 10:15
Kevin McFarlane3-Apr-06 10:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.