Skip to content
Erik Van Hamme edited this page Apr 6, 2020 · 7 revisions

Style guide

File naming

File names are all lowercase, with - as word separator. Headers end in .hpp. So, a header could be called this-is-example-header.hpp.

Line width

In general, line width is limited to 80 characters, although a few characters more are allowed if it improves readability.

Exceptions can be made for boilerplate code (for example, see the end of render-manager.cpp)

Indentation

  1. Indentation is spaces, not tabs. Usually 4 spaces for functions, classes and control flow structures.
  2. When function arguments are broken, the arguments on each subsequent line are indented with 4 spaces.
  3. No additional indentation inside namespace.
  4. public, private, and protected, are indented just 2 spaces. So it looks like this:
class ABC
{
  public:
    ABC();
  private:
    void foo();
};

Naming

Class, method and variable names are all in snake_case. Class names should end in _t.

Braces

  1. Braces are necessary in all cases except for single-line ifs (Both condition and statement are single-line).
  2. Curly braces should usually begin on a new line. Exceptions are a series of single-line if/else if/else chains.

Spaces

Spaces are used:

  1. Before and after operators
  2. Between control flow keywords and the opening brace after them.

Headers

  1. Use #pragma once instead of the traditional include guards.