Click here to Skip to main content
15,895,746 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)


 
Generalan underscore and plain english (camel case) Pin
fabulous7-Apr-06 16:10
fabulous7-Apr-06 16:10 
GeneralHN Pin
vobject7-Apr-06 1:53
vobject7-Apr-06 1:53 
GeneralJust us GUIDs Pin
Troy Marchand6-Apr-06 18:23
sitebuilderTroy Marchand6-Apr-06 18:23 
JokeI don't have local variables Pin
Marek.T6-Apr-06 11:52
Marek.T6-Apr-06 11:52 
GeneralK.I.S.S. Pin
David Veeneman6-Apr-06 9:27
David Veeneman6-Apr-06 9:27 
GeneralRe: K.I.S.S. Pin
Alvaro Mendez7-Apr-06 5:08
Alvaro Mendez7-Apr-06 5:08 
GeneralUsing C# .Net then use Microsoft's Pin
Daniel Vaughan6-Apr-06 3:22
Daniel Vaughan6-Apr-06 3:22 
JokeUsing C++ and using C# style Pin
FocusedWolf7-Apr-06 5:22
FocusedWolf7-Apr-06 5:22 
GeneralRe: Using C++ and using C# style Pin
vobject9-Apr-06 21:42
vobject9-Apr-06 21:42 
GeneralMe Pin
Trance Junkie4-Apr-06 23:51
Trance Junkie4-Apr-06 23:51 
GeneralRe: Me Pin
Bob Stanneveld5-Apr-06 23:34
Bob Stanneveld5-Apr-06 23:34 
GeneralRe: Me Pin
Malik Nasir31-May-06 0:07
Malik Nasir31-May-06 0:07 
GeneralMy use of "Scope and Hungarian prefix" Pin
Kochise4-Apr-06 21:40
Kochise4-Apr-06 21:40 
To keep some consistency of my source code and help people understanding it afterward, I use I slightly modified "Scope and Hungarian prefix" notation, I explained in my CSkinProgress control :

// g_Global      : g_ = Global
// i_Input       : i_ = Input
// no z...
// m_Member      : m_ = Member
// o_Output      : o_ = Output
// l_Local       : l_ = Local
// ...           : use your imagination

// aArray        : a  = Array    (array)
// bBool         : b  = Boolean  (boolean, TRUE/FALSE)
// cConstant     : c  = Constant (constant, whatever...)
// dDefine       : d  = Define   (simple define or defined value)
// eEnum         : e  = Enum     (enum list element)
// iIterator     : i  = Iterator (STL iterator)
// nNumber       : n  = Number   (char, long, int, whatever...)
// oObject       : o  = Object   (C++ class)
// pPointer      : p  = Pointer  (typicaly a 32 bits ulong address)
// sStruct       : s  = Struct   (structure)
// tTemplate     : t  = Template (template)
// uUnion        : u  = Union    (join two or more values of the same size under a common name)
// vVector       : v  = Vector   (STL vector, mostly like an array)

// poRemoteClass : po = Pointer on Object
// cdConstantDef : cd = Constant Define, typicaly a constant defined value
// usUnionStruct : us = Union of Structures
// ...           : use your imagination

// o_psBitmap    : CBitmap::GetBitmap((BITMAP*) o_psBitmap); // s = BITMAP, p = *, o_ means it's an output


For private/protected members of a class, I start with 'mp_' (means MemberPrivate_). All these informations, though not used by the compiler, could help to understand the focus and life time of a variable (g_ stands for the whole application life time, m_ for the class life time, l_ for the method life time, ...).

The hungarian prefix helps to remind the reader what kind of variable it is. You don't always have the constructor/declaration on screen (even if all methods are supposed to fits in one screen), so it's kind to know what you are dealing with. Not every IDE have IntelliSense, I sometimes code on notepad...

This is also quite useful to chage a variable from a scope and type to another, without changing other variable. For instance, changing the mp_nSerial to m_nSerial when it has to become public, or m_nSerial to m_oStrSerial when there is no more enough space on the int value and/or you may support characters in your serial.

Don't forget you cannot use a int like a string. You may not do m_nSerial.Format("%d", GetSerial()), but m_nSerial = GetSerial() instead... That's where hungarian prefix helps, it prevent you from even thinking doing some kind of .Format(stuff) Smile | :)

Things to read though :

http://www.joelonsoftware.com/printerFriendly/articles/Wrong.html

http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=35396

Kochise

In Code we trust !

-- modified at 3:43 Wednesday 5th April, 2006
GeneralDatagrid new line Pin
Macky1004-Apr-06 3:26
Macky1004-Apr-06 3:26 
GeneralRe: Datagrid new line Pin
Arch4ngel4-Apr-06 10:52
Arch4ngel4-Apr-06 10:52 
GeneralCListCtrl Pin
Phil J Pearson4-Apr-06 1:11
Phil J Pearson4-Apr-06 1:11 
GeneralX Pin
thrakazog3-Apr-06 9:17
thrakazog3-Apr-06 9:17 
GeneralRe: X Pin
Rohit Wason3-Apr-06 9:58
Rohit Wason3-Apr-06 9:58 
GeneralRe: X Pin
Gary R. Wheeler3-Apr-06 15:40
Gary R. Wheeler3-Apr-06 15:40 
GeneralV Pin
hairy_hats7-Apr-06 5:19
hairy_hats7-Apr-06 5:19 
GeneralRe: X Pin
toxcct4-Apr-06 0:58
toxcct4-Apr-06 0:58 
GeneralRe: X Pin
KarstenK4-Apr-06 2:58
mveKarstenK4-Apr-06 2:58 
GeneralRe: X Pin
KevinHall4-Apr-06 4:59
KevinHall4-Apr-06 4:59 
GeneralRe: X Pin
WillemM5-Apr-06 21:09
WillemM5-Apr-06 21:09 
GeneralRe: X Pin
KevinHall6-Apr-06 7:57
KevinHall6-Apr-06 7:57 

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.