Skip to content

Style Guide

이영진 edited this page Dec 11, 2023 · 4 revisions

Rule of 3/5/0

Every class has to follow the rule of 5 or rule or 0.

This means that every class should either explicitly implement or delete a destructor, a copy constructor, a copy assignment, a move constructor, and a move assignment or none of them.

Static classes

For static classes which shouldn't be created an instance of, make a public default constructor and delete it.

Specifiers

[[nodiscard]] : This is recommended where necessary.

noexcept : This is recommended where necessary for all functions at the momment. This can be changed in the future.

constexpr : Shouldn't put constexpr everywhere, only add it where the semantics is right. (If you are almost certain it can be constexpr.)

Header including order

Headers should be included as the following order, with an additional line spacing between the categories. The order is local to global, in a nutshell.

  1. If it is a cpp file of a class, the header file corresponding to it.
  2. pch.h (The precompiled header)
  3. Header files in the same directory.
  4. Header files in the same project.
  5. Header files from other projects.
  6. Header files from dependencies.
  7. System headers.

Class member & method declaration order

This is not mandatory, the primary rule is to make it readable as possible to the user. Generally, put constructors and the big 5 at the front, then public > protected > private. In each access modifiers, the order is: type definitions, static members and methods, non-static members and methods

  1. public enums, classes and typedefs/usings
  2. (regardless of the access modifiers) constructors, destructor, copy constructor, move constructor, copy assignment, and move assignment
  3. public static members and methods (Creation related methods come first)
  4. public non-static members and methods (Getters and setters come last)
  5. (Similar to public stuff) protected enums and classes > static members and methods > non-static members and methods
  6. (Similar to public stuff) private enums and classes > static members and methods > non-static members and methods
  7. friend declarations

Naming convention

  • All functions and type names use PascalCase.
  • Local variables use camelCase.
  • Compile-time constants and macros use SCREAMING_SNAKE_CASE.
  • Member variables has m_ prefix (m_MemberName).
  • Static variables has s_ prefix (s_StaticMemberName).

Clone this wiki locally