Click here to Skip to main content
15,923,389 members

Survey Results

Naming conventions in your code   [Edit]

Survey period: 31 Jan 2005 to 6 Feb 2005

What notations do you use when naming variables? (And have things changed since we first asked back in 2003?)

OptionVotes% 
Hungarian notation with prefixes (strFirstName, m_nNumber etc)77140.86
Hungarian notation without prefixes ( _nNumber etc)492.60
Camel Caps (numberOfDays, isValid etc)72538.42
Pascal case (BackColor, DataSet)22511.92
C-style (this_is_a_variable)492.60
FORTRAN case (all caps)30.16

View optional text answers (82 answers)


 
GeneralProject and language/library consistency Pin
Mike Dimmick5-Feb-05 6:02
Mike Dimmick5-Feb-05 6:02 
When I pick up a project, I try to be consistent with the conventions already used in that project. If you use different conventions, you have a context switch problem - it can take time to adjust when you come across a section of code with a different convention.

For VB6 apps that usually means the VB style of Hungarian - based only on the physical type of the variable, str for strings. This is virtually a requirement as VB6's type model is so weak - you really do need to know the actual types at the point of use, otherwise you run the risk of making a type error.

For C/C++ code I generally use Hungarian prefixes and try to use more of a logical type prefix in my own code. I don't bother with Hungarian prefixes on structures or objects because the compiler's type checking catches mistakes.

For C# code I don't use prefixes because the type checking is strict enough to catch all type errors I might make. It's also fine to omit prefixes in VB.NET if you've turned on Option Strict.

I don't agree that you should change the style of existing code when you pick up a project. Doing this causes noise in your source control difference/merge tool. I like to review what other people have changed since I last saw a particular file, and I like to review the changes I've made since my baseline. Any change is risky (obviously different changes have different risk levels) and it's preferable not to introduce unnecessary risks. There are generally higher priorities than changing code to conform to what are generally slightly arbitrary standards. If the code is unintelligible, then yes, you may need to rewrite it. On the other hand, if it's unintelligible, you may be unable to understand it sufficiently well to rewrite it successfully.

Objections to Hungarian often include the question of what you do if you change the type of a variable - do you need to rename the variable and all its uses? Firstly this is only a problem if you've encoded the physical type of the variable - int, long, whatever. If you've changed the logical type of the variable, you've changed its meaning, and you need to very carefully review where it's used.

If you're in a non-type-safe environment where you have to encode the physical type of the variable in the name, you need to carefully review every place it's used in order to ensure you haven't introduced a type error. I'm talking about things like silent narrowing conversions as featured in VB6.

Stability. What an interesting concept. -- Chris Maunder
GeneralDepends on what i'm doing. Pin
Shog94-Feb-05 13:03
sitebuilderShog94-Feb-05 13:03 
GeneralMixing Stuff Pin
Alejandro K.4-Feb-05 1:53
Alejandro K.4-Feb-05 1:53 
GeneralRe: Mixing Stuff Pin
Paranoicus Maximus6-Feb-05 17:21
Paranoicus Maximus6-Feb-05 17:21 
GeneralGood poll! Pin
thwart3-Feb-05 4:07
thwart3-Feb-05 4:07 
GeneralRe: Good poll! Pin
gehkadl3-Feb-05 6:22
gehkadl3-Feb-05 6:22 
GeneralRe: Good poll! Pin
Michael Dunn3-Feb-05 7:50
sitebuilderMichael Dunn3-Feb-05 7:50 
GeneralRe: Good poll! Pin
gehkadl3-Feb-05 21:07
gehkadl3-Feb-05 21:07 
GeneralRe: Good poll! Pin
Ravi Bhavnani5-Feb-05 9:29
professionalRavi Bhavnani5-Feb-05 9:29 
GeneralThis should be multiply selection poll Pin
Igor Urdenko2-Feb-05 21:20
Igor Urdenko2-Feb-05 21:20 
GeneralDitto Pin
Grimolfr3-Feb-05 4:30
Grimolfr3-Feb-05 4:30 
GeneralRe: Ditto Pin
malharone3-Feb-05 6:30
malharone3-Feb-05 6:30 
GeneralRe: Ditto Pin
Grimolfr3-Feb-05 8:28
Grimolfr3-Feb-05 8:28 
GeneralEspanol? Pin
Michael Dunn2-Feb-05 13:45
sitebuilderMichael Dunn2-Feb-05 13:45 
GeneralRe: Espanol? Pin
Alvaro Mendez3-Feb-05 6:01
Alvaro Mendez3-Feb-05 6:01 
GeneralDepends on platform Pin
Madhu Kampurath1-Feb-05 17:52
Madhu Kampurath1-Feb-05 17:52 
GeneralRe: Depends on platform Pin
Ravi Bhavnani2-Feb-05 3:27
professionalRavi Bhavnani2-Feb-05 3:27 
GeneralRe: Depends on platform Pin
Anonymous2-Feb-05 4:57
Anonymous2-Feb-05 4:57 
GeneralcamelCase vs Hungarian Pin
Phil Sidari1-Feb-05 10:07
Phil Sidari1-Feb-05 10:07 
GeneralRe: camelCase vs Hungarian Pin
Jörgen Sigvardsson1-Feb-05 11:14
Jörgen Sigvardsson1-Feb-05 11:14 
GeneralRe: camelCase vs Hungarian Pin
mlkeS1-Feb-05 15:37
mlkeS1-Feb-05 15:37 
GeneralRe: camelCase vs Hungarian Pin
slimtim1-Feb-05 20:00
slimtim1-Feb-05 20:00 
GeneralRe: camelCase vs Hungarian Pin
James R. Twine2-Feb-05 6:03
James R. Twine2-Feb-05 6:03 
GeneralRe: camelCase vs Hungarian Pin
slimtim2-Feb-05 9:10
slimtim2-Feb-05 9:10 
GeneralRe: camelCase vs Hungarian Pin
Dale Thompson2-Feb-05 12:34
Dale Thompson2-Feb-05 12:34 

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.