There are many different styles of naming the entities in your code, but the most important part of it is that you define what your style is and stick to it consistently, naming all the entities of the same type in the same way.
Naming style example
Here’s one example of the code style, the one that I personally use in my current projects.
Before I give it, let me explain what the camel-casing is, which I refer to in almost every line 🙂
Camel-casing is one of the methods of creating identifiers that combine several words. Following the camel-casing style:
- the words are written in small letters;
- each word (but the first in many situations) starts with a capital letter;
- no underscores are used.
So, now to the example:
- start with a small letter, camel-casing in case of multiple words (e.g.
var, myVariable, count, numberOfPoints);
i,j,k,lfor the simple integer loop indices (I tend to use
iin cases of signed
jin cases of
unsignedwhen there is one loop without nesting);
- name starts with
pfor a pointer, with
ppfor a pointer to pointer, etc. (e.g.
pMyPointer, pSize, ppData, ppMyArray).
Structure and class names:
start with a capital letter, camel-casing (e.g.
MyClass, HeatColorizer, PointInfo).
start with a capital letter
I, camel-casing (e.g.
Member method names:
start with a small letter, represent an ACTION, camel-casing (e.g.
MyClass::doAction, IColorizer::colorizeVal, Car::startEngine).
Free function names:
Start with a capital letter, represent an ACTION, camel-casing (e.g.
PerformProcedure, CreateColorizer, SendMessage).
Named constants and preprocessor defines
Named constants and preprocessor
#defines (including header protection, see section II of my last post) are the only exceptions from the camel-casing, they are written in all-caps with using underscores between the words (e.g.
MY_DEFINE, MAX_LENGTH, ICOLORIZER_H_).
it is not that important which style you use for your solo projects, just pick one and stick to it. However, it is very important that the bigger projects will have consistent style through all the source files and packages, thus, the naming style is one of the required decisions to be made at the group/team level.