-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Naming
C is a Spartan language, and so should your naming be.
Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like
ThisVariableIsATemporaryCounter
A C programmer would call that variable
tmp
which is easier to write, and easy to understand.
HOWEVER, while mixed-case names are frowned upon, descriptive names for global variables are a must.
To call a global function foo
is a shooting offense.
GLOBAL variables (to be used only if you really need them) need to have descriptive names, as do global functions.
If you have a function that counts the number of active users, you should call that
count_active_users()
or similar, you should not call it
cntusr()
Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged - the compiler knows the types anyway and can check those, and it only confuses the programmer.
LOCAL variable names should be short, and to the point.
If you have some random integer loop counter, it should probably be called i
.
Calling it loop_counter
is non-productive, if there is no chance of it being mis-understood.
Similarly, tmp
can be just about any type of variable that is used to hold a temporary value.
If you are afraid to mix up your local variable names, you have another problem, which is called the function-growth-hormone-imbalance syndrome. See chapter 1.6 (Functions).
0.1 - Betty-style usage
0.2 - Betty-doc usage
0.3 - References
1.1 - Indentation
1.2 - Breaking long lines and strings
1.3 - Placing Braces
1.4 - Placing Spaces
1.5 - Naming
1.6 - Functions
1.7 - Commenting
1.8 - Macros and Enums
1.9 - Header files
2.1 - Functions
2.2 - Data structures
3.1 - Emacs
3.2 - Vim
3.3 - Atom