Naming Conventions

From OpenMW Wiki
Revision as of 13:08, 2 November 2018 by Dbpiper (talk | contribs) (Change "had" to "have"; that is, fix minor grammatical error.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In the beginning of OpenMW we did not have any naming conventions which resulted in substantial inconsistencies. This page tries to codify the conventions that are most commonly used in the code base. Please stick to them, even if the code in the neighbourhood of what you are working on is not.

Files[edit]

header files: somefile.hpp

source files: somefile.cpp

No CamelCase and no underscores, please.

Names[edit]

Namespaces[edit]

Example: ThisIsANamespace

Namespaces in apps/openmw will have a MW-prefix (MWThisIsANamespace). Obviously you should try to keep these names short, but don't use hard to read abbreviations.

Classes[edit]

Example: ThisIsAClass

Functions[edit]

Example: thisIsAFunction

Local Variables & Parameters[edit]

Example: thisIsAVariable

Member Variables[edit]

Non-static: mThisIsAVariable

Static: sThisIsAVariable

Note that formally the name of the variable would still be thisIsAVariable. The m and the s are scope sigils. Some other languages (e.g. Ruby) provide these as part of the syntax. C doesn't, so we have to encode them in the name. And no, this is not Hungarian notation.

Global Variables[edit]

Shame on you!

Enums[edit]

Example:

  • TypePrefix_SomeName
  • TypePrefix_SomeOtherName
  • TypePrefix_AndSomeMore

The TypePrefix should be chosen appropriately for the purpose of the enum. Don't use all uppercase names. These would make the enums look like preprocessor constants.

Preprocessor constants[edit]

Example: THISISACONSTANT

Since preprocessor constants are the only part of the language that does not respect namespaces, these must be clearly distinguished from everything else.

Don't use these for anything but include guards and conditional compiling.


Acronyms[edit]

Acronyms in names should follow the guidelines on this page too, even if that is not how you would normally write them, e.g.: a class representing a NPC would be called Npc. Otherwise it would look like a preprocessor macro.

Abbreviations[edit]

Please avoid cryptic abbreviations. iter and i are okay. Well known acronyms from the RPG terminology are okay too (but see above for advice on capitalisation). Other abbreviations should be avoided. Don't be afraid of long names!