Re: How to name variables in a program?



> Having a strong convention for naming your variables in your program
> is an important issue often overlooked.
> Can anyone point me to a good source on the web dealing with this
> issue?

Ever since I picked up the book Windows programming book by Petzold, I have
been using something called "Hungarian notation":
http://en.wikipedia.org/wiki/Hungarian_notation

Although it is by no means a guide on picking good names for your variables,
this convention works with prefixes to indicate variable type.

When I have a local variable which is nothing more than a temporary variable
I use just the prefix, so unlike what philip states, I do get variable names
such as i and l. To give an example:

i = SomeFunction(szArg1, iArg2, iArg3);
if ( i == 0 )
...;

(note that szArg1, iArg2 and iArg3 are terrible names you should never use
in a real program)

Other conventions I use:

- every structure I define, I trail with a comment indicating the
hungarian code
- prefix global variables with g_
- prefix pointers with lp (this stands for "long pointer" and is still
reminiscent of the 16 bit Windows days)

Good luck,

--
Martijn
http://www.sereneconcepts.nl


.



Relevant Pages

  • Re: silent semantic changes with reiser4
    ... was just a style convention for metafiles, ... prefix with a subdirectory ... > that one could ls it to see all the builtins supported by a given ... applications) don't trip over this stuff, it is a moby nightmare security ...
    (Linux-Kernel)
  • .NET Naming Guidelines (C#)
    ... The recommendations ... Member Variable Prefix: Most of the people still use (and like the ... Use "m" as it also matches the convention generally followed ... Hungarian Notation / Type Prefix: This is now regarded as a bad ...
    (microsoft.public.dotnet.general)
  • Re: How to name variables in a program?
    ... > Having a strong convention for naming your variables in your program is an ... wrote what by looking at its structure, style, format, or naming ... - don't use l, i, O, etc. for local variables. ... - prefix strings with s or str ...
    (comp.programming)
  • Re: silent semantic changes with reiser4
    ... make the standard unix metafiles less intrusive on the namespace. ... was just a style convention for metafiles, ... prefix with a subdirectory ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Again: Please hear my plea: print without softspace
    ... The name 'self' is just a convention. ... a very common naming convention suggests using an 'm_' prefix ... Changing the underscore to a dot in C++ gives the same result as using ... slightly different things - but in readability terms its much the same ...
    (comp.lang.python)