Next: Class Member Variables
Up: General Naming Conventions
Previous: Variables
  Contents
To make your life easier we suggest the use of the simplified Hungarian
notation for variable naming. Consider the problem of dealing with a
thousand-line function that you wrote last year. That functions should
never be that long in first place is besides the point. Assume you are
staring at a variable name wondering what the type of the variable is.
The variable happens to be declared on the first line of the function
and you are viewing the file through a very slow telnet connection.
If you have lots of time to waste you might just decide to scroll and
wait. The alternate solution would have been to use Hungarian notation
for variable naming. An Hungarian Microsoft programmer developed the
notation (hence the name). The idea is to prefix variable names with
the type of the variable. Microsoft has simplified Hungarian Notation
to become Simplified Hungarian Notation. For our purposes all
Microsoft specific content has been removed. The recommended variable
naming conventions are listed in Table
.
The simplified version was derived since the true Hungarian Notation
is too cumbersome. It accounts for less than 32-bit operating systems
wherein you are required to specify things like whether a pointer is
far or near. In addition it also accounts for signing and bit length
of types.
Table:
Simplified Hungarian Notation.
| Prefix |
Type |
Description |
Example |
| n |
int |
any integer type |
nCount |
| ch |
char |
any character type |
chLetter |
| f |
float, double |
floating point |
fPercent |
| b |
bool |
any boolean type |
bDone |
| l |
long |
any long type |
lDistance |
| p |
* |
any pointer |
pObject, pnCount |
| sz |
* |
nul terminated string of characters |
szText |
| pfn |
* |
function pointer |
pfnProgress |
| h |
handle |
handle to something |
hMenu |
|
Variable names can then be constructed from combinations of the prefix
list given in Table
. The programmer
should use common sense to determine which combinations make sense.
Additional examples are listed in Table
.
Table:
Example of type specific variable naming.
| Type |
Example |
| int |
nCount |
| int* |
pnCount |
| bool* |
pbDone |
| bool& |
bDone |
|
A paradox arises while using Hungarian Notation of any variation.
What do you do with user defined types? You do not want to invent
your own prefix because it may not make sense to Waldo, but by not
prefixing a variable with something you are not helping the situation
either. The best solution is to name your variables in such a way
that you do not need to use Hungarian Notation to decipher its type
Subsections
Next: Class Member Variables
Up: General Naming Conventions
Previous: Variables
  Contents
Falko Kuester
2001-08-24