Click here to Skip to main content
15,911,646 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
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 
Ryan Roberts wrote:
It's different from Pascal cased, so you dont have to think of variable names in circumstances that don't require it.


public void Stuff()
{
ThingAmiBob thingAmiBob = new ThingAmiBob();
}

Is better in my opinion than

public void Stuff()
{
ThingAmiBob MyThingAmiBob = new ThingAmiBob();
}


I think it's generally considered bad style to have an instance variable name that differs from its type name only in case. A type name represents the name of... well, a type! When creating an instance of a type, the instance name should be specific enough to differentiate it from other instances of the same type, as well as from the type itself, for that matter.

There are times when it is tempting to break this rule. For example, say you are passing a timer to a method:

public void SomeMethod(Timer timer)
{
}


The context could be general enough till it becomes difficult to think up a name for the parameter that somehow distinquishes it from its type. The purpose of the method may give us a clue, though, and we could rename the parameter something like pollingTimer, or whatever. Sometimes its kinda tough, and you may wind up just naming the parameter t or tmr, if you want to strictly avoid having a variable name differ from its type name only in case. But that may not be any better.

So my question for everyone is what would you do in the above situation when it just isn't clear what a parameter should be named?


-- modified at 15:36 Tuesday 4th April, 2006
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 
Generalwhat, no m_??? Pin
Marc Clifton3-Apr-06 0:54
mvaMarc Clifton3-Apr-06 0:54 
GeneralRe: what, no m_??? Pin
Carsten Zeumer3-Apr-06 1:57
Carsten Zeumer3-Apr-06 1:57 
GeneralRe: what, no m_??? Pin
Marc Clifton3-Apr-06 2:16
mvaMarc Clifton3-Apr-06 2:16 
GeneralRe: what, no m_??? Pin
Carsten Zeumer3-Apr-06 3:21
Carsten Zeumer3-Apr-06 3:21 
GeneralRe: what, no m_??? Pin
Marc Clifton3-Apr-06 3:35
mvaMarc Clifton3-Apr-06 3:35 
GeneralRe: what, no m_??? Pin
Chris Maunder3-Apr-06 3:32
cofounderChris Maunder3-Apr-06 3:32 
GeneralRe: what, no m_??? Pin
Furty4-Apr-06 13:31
Furty4-Apr-06 13:31 

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.