Naming Conventions

Back to Code Conventions

Naming standards, above all else, allow us to quickly understand the meanings of each others' code, because basic assumptions apply everywhere. This is especially important in large projects with multiple programmers interacting over and relying on each others' work.

The following rules attempt to generalize naming conventions across all languages that we have seen inside the project (C, C++, Python). Certain object-oriented features do not apply to C, and these should be ignored.

  1. Variables and methods should be named beginning with a lowercase letter and in camel-case.

Common practice in object-oriented languages. The lowercase letter at the beginning is the most important choice here.

e.g. updateNeighbors() or myPrivateClassVariable

  1. Global functions and routines should be named in lowercase, with english words separated by underscores. e.g. my_global_function()

Common practice for C programmers. The use of underscores clearly separates these names from object methods, indicating statelessness.

e.g. sensor_initialization_routine()

  1. Types should be named beginning with an uppercase letter and thereafter in camel-case.

Common practice in C++ and even a requirement in several other object-oriented languages.

e.g. DoublyLinkedList

  1. Names must not be abbreviated. One-letter variable names, especially, should be avoided.

It is less important that variables be easy to type, and far more important that their meaning be clear based on their name. In addition, we must remember there is no speed penalty for using a long variable name. There is a short list of commonly-understood abbreviations that are permissible, including max and min. If you think you have found another one, you could be right, but make your decisions carefully.

There is also one practical exception where one-letter variables may improve readability, being iteration in for loops. If a one-letter variable is appropriate, use i, j, k, and l in that order.

e.g. currentStepNumber, instead of curStepNum

  1. The following prefixes must be applied to variables as they apply.
Application Prefix Example
Static Data Members their theirTotalEstimation
Global Variables the theWindow
Constants c cMaximumNumberOfSteps
Private Class Variable my myBoundingBox

If a variable fits more than one of these categories, they have been organized here in decreasing order of importance. Choose the highest satisfying entry in the table.