- Indent style is Allman (BSD) -like, ie. brace on the next line from a control statement, indented on the same level. In switch-case statements the cases are on the same indent level as the switch statement.
- Indents use 4 spaces instead of tabs. Indents on empty lines should not be kept.
- Class and struct names are in camelcase beginning with an uppercase letter. They should be nouns. For example
DebugRenderer, FreeTypeLibrary, Graphics.
- Functions are likewise in upper-camelcase. For example
CreateComponent, SetLinearRestThreshold.
- Variables are in lower-camelcase. Member variables have an underscore appended. For example
numContacts, randomSeed_.
- Constants and enumerations are in uppercase. For example
Vector3::ZERO or PASS_SHADOW.
- Pointers and references append the * or & symbol to the type without a space in between. For example
Drawable* drawable, Serializer& dest.
- The macro
NULL and 0 should not be used for null pointers, nullptr is used instead.
override is used wherever possible.
using is used instead of typedef in type declarations.
enum class is used wherever possible.
- Use a singular type names for enums unless its values are bit fields.
- Use a plural type names for enums with bit fields as values.
- Don't use suffixes like "Enum", "Flags" and so on
- Class definitions proceed in the following order:
- public constructors and the destructor
- public virtual functions
- public non-virtual member functions
- public static functions
- public member variables
- public static variables
- repeat all of the above in order for protected definitions, and finally private
- Header files are commented using one-line comments beginning with /// to mark them for Doxygen.
- Inline functions are defined inside the class definitions where possible, without using the inline keyword.
Use this brief checklist to keep code style consistent among contributions and contributors:
- Prefer inplace member initialization to initializer lists.
- Prefer range-based
for to old style for unless index or iterator is used by itself.
- Avoid
auto unless it greatly reduces a code size. Examples: auto iter = variables.Find(name);
for (auto& variable : variables) { }