Click here to Skip to main content
15,902,939 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: Everyone seems to use a mix Pin
stephenbayer3-Apr-06 9:36
stephenbayer3-Apr-06 9:36 
GeneralRe: Everyone seems to use a mix Pin
Gary R. Wheeler3-Apr-06 15:34
Gary R. Wheeler3-Apr-06 15:34 
GeneralWhy camelCased? Pin
QuiJohn3-Apr-06 2:32
QuiJohn3-Apr-06 2:32 
GeneralRe: Why camelCased? Pin
Ryan Roberts3-Apr-06 3:01
Ryan Roberts3-Apr-06 3:01 
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 
Camel casing is the way to go. Its primary function is to create a variable name from concatenated words and still be easy to read.

Who wants type info or.. scope (wtf is that scope crap?!!? who does that!?) all over the code. Nasty business that, it's just fluff that your brain has to process before you get to useful part, the name of the variable. While it may be very dubiously useful in a typeless language it's still just filling up the screen with fluff. The type of the variable should be implied implicitly because of how it is used. I dont have any trouble reading it (it is the MS standard - see dotnet naming convention doc).

On the subject of case sensitivity. It's a good thing, not because it allows you to have two variables with the same name differing only be case (though that is cool, why? read on) but because anyone who uses that member will all call it in a consistent way.

There'll be no:
foo.Hello() - Bobs code
foo.hello() - Sally's code
foo.HeLLO() - Some idiots code

Cause the compiler will force Bob, Sally and the idiot to all write foo.Hello().

A benefit of being able to have variables with the same name differing by case only is best demonstrated with the field property example.

long customerId;

public long CustomerId{
get{ return customerId; }
}

Users of the API only ever see one member (CustomerId). Meanwhile your not forced into a situation where u have to use stupid prefixes like m_. Now because ur using a case sensitive language and u've used camelCasing u know what customerId is for because it starts with a lower case letter. And u know what CustomerId is for because it starts with an uppercase letter. And the relationship between the two is obvious because they have (almost) the exactly same name.

I like the naming convention used by MS in the dotnet framework. A lot of thought went in to it and it's consistently often allows me to guess the names of things without ever needing to go looking stuff up. If chaos is your preferred environment, keep using vbscript or some trash.

Someone needs to send these VB programmers to skool!

Note: Year i'm aware i'm using a mixture of Pascal and camel. My rule of thumb is camel for local vars, parameter arg names etc. Public properties, methods, class names interface names etc all get Pascal casing.

[worldspawn]

-- modified at 3:17 Tuesday 4th April, 2006
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 
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 

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.