Code Style

Entity naming style

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:

Variable names:

  • start with a small letter, camel-casing in case of multiple words (e.g. var, myVariable, count, numberOfPoints);
  • one-letter i,j,k,l for the simple integer loop indices (I tend to use i in cases of signed int and j in cases of unsigned when there is one loop without nesting);
  • name starts with p for a pointer, with pp for 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).

Interface names:

start with a capital letter I, camel-casing (e.g. IMyInterface, IColorizer).

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_).

Once again,

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.


2 thoughts on “Entity naming style

  1. Instead of “camel-casing”, I write “camelCasing”. Nobody ever asked for clarification, so that seems self-explanatory. Similarly, the other writing styles you mention also have (somewhat) evocative names, such as PascalCase and SHOUT_CASE.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s