-
-
All files with C++ code must be named in UpperCamelCase.
Header (.h) and implementation (.cpp) files must be named according to the following rules:
-
If a header file contains structures, then the header file and the implementation file must be named according to the main structure in the meaning of the code in this file.
-- code
// in header file struct Position { float m_x { }; float m_y { }; float m_z { }; void moveTo(const float& x, const float& y, const float& z) noexcept; };
-- end code
-- files structure
-> Position.h
-> Position.cpp-- end files structure
-
If a header file does not contain structures, its name should clearly indicate its purpose.
-- code
// in header file enum class TextureType { // ... }; enum class AttachmentType { // ... };
-- end code
-- files structure
-> DataTypes.h
-> DataTypes.cpp-- end files structure
-
-
All namespaces, whether structs, classes, enums, unions, namespaces, or anything else, must be named according to the UpperCamelCase.
-- code
-- end code
struct MyStruct { }; enum class MyEnum { }; namespace MyNamespace { }
-
Each variable must be grammatically correct in English and also have a comprehensive name in terms of meaning.
- Local variables must be named according to the lowerCamelCase.
-- code
-- end code
void myFunc() { float myLocalVariable { }; }
- Non-static member variables (except events and callbacks) of classes, structures or unions must begin with the prefix m_. The prefix must be followed by the variable name in the lowerCamelCase.
-- code
-- end code
struct MyStruct { float m_myMemberVaribale { }; };
- Static member variables (except events and callbacks) of classes, structures or unions must begin with the prefix s_. The prefix must be followed by the variable name in the lowerCamelCase.
-- code
-- end code
struct MyStruct { static inline float s_myMemberVaribale { }; };
- Member variables denoting an events or callbacks must be named according to lowerCamelCase without any prefixes.
-- code
-- end code
struct Screen { Event<void()> onClicked; std::function<void()> onTouched; };
- Variables in template arguments must be named according to UpperCamelCase.
If the type name in the template completely matches the possible name of the variable, then the letter T must be at the beginning of the name. -- code-- end codeenum class FormatType { }; template<typename SomeType, size_t MyUInt, FormatType TFromatType> struct MyStruct { };
- Macros must be named according to either lower_snake_case or UPPER_SNAKE_CASE.
-- code
-- end code
#define MY_MACRO_0 #define my_macro_1
- constexpr variables, as well as uses and typedefs, must be named according to lower_snake_case.
-- code
-- end code
template<typename T> struct MyStruct { using my_type = T; typedef T my_type_alias; static constexpr inline std::size_t num_dimensions = 3; };
- Local variables must be named according to the lowerCamelCase.
-- code
-
All functions must be named according to the lowerCamelCase
-- code
-- end code
void myFunc() { // ... }
-
If an abbreviation appears at the beginning of a variable or function name, all letters of the abbreviation are written in lowercase.
-- code
-- end code In any other place in the name of a variable or function, all letters of the abbreviation are written in capital letters. -- code
struct AABB { AABB* m_aabbMember { }; } void aabbFunc() { // ... }
-- end codestruct AABB { AABB* m_parentAABB { }; } void resizeAABB(AABB& aabb) { // ... }
-
All files with C++ code must be named in UpperCamelCase.
Header (.h) and implementation (.cpp) files must be named according to the following rules:
-
-
There should be no spaces after the starting (left paren) and before the ending (right paren) brackets.
If there are no arguments, no spaces are included. -- code-- end codevoid doSomething(float a) { try { } catch(const std::exception& e) { } }
-
There should be no space before the semicolons, and there should be one after them.
-- code
-- end code
void doSomething() { for(int i = 0; i < 3; ++i) { } }
-
There must be one space before and after the use of subtraction, addition, division, multiplication, assignment, equality and inequality operators.
-- code
-- end code
void doSomething() { int a = 3; int b = 5; int c = a - b + (a * a); }
-
There must be no spaces after the opening square bracket and before the closing square bracket.
If there are no arguments, no spaces are included. -- code-- end codevoid doSomething() { auto [a, b] = std::make_tuple(1, 2); }
-
There should be no spaces before the commas (for multiple listings), and there should be one space after each comma.
If there are no arguments, no spaces are included. -- code-- end codevoid doSomething(float a, float b) { }
-
There must be no spaces after the opening square bracket and before the closing square bracket.
There should be no spaces before the commas (for multiple listings), and there should be one space after each comma.
If there are no arguments, no spaces are included. -- code-- end codevoid doSomething() { std::unordered_map<int, int> myMap; }
-
There should be one space before the initial curly brace and before the final curly brace in the initialization expression.
If there are no arguments, no spaces are included. -- code-- end code If a multi-line initialization in curly braces is assumed, then the starting curly brace can be either on a new line or on the same line as the initialization. -- codevoid doSomething() { auto myVar = { 3, 4, 5 }; }
-- end code The beginning brace of a lambda expression can be placed either on a new line or on the same line as the declaration of the lambda expression.void doSomething() { auto myVar0 = { 3, 4, 5 }; auto myVar1 = { 3, 4, 5 }; }
When declaring a lambda expression on a single line, there must be one space after the beginning brace and before the ending brace.
When declaring a lambda expression, there must be a space before the starting curly brace. -- code-- end code The curly braces of the body of functions, namespaces, unions, structures, and classes must start on a new line. -- codevoid doSomething() { auto myLambda0 = []() { return 2 + 2; }; auto myLambda1 = []() { return 2 + 2; }; auto myLambda2 = []() { return 2 + 2; }; }
-- end codenamespace MyNamespace { struct MyString { union IntenalBuffer { } } void doSomething() { } }
-
Spaces are not used before or after references to namespaces, structures, unions, classes, and static members.
-- code
-- end code
void doSomething() { Core::Internal::doSomethingOther(); }
-
There must be a space before and after the colons.
-- code
-- end code
void doSomething() { std::vector<int> values { 1, 2, 3 }; for(const auto& v : values) { } }
-
There should be no spaces after the starting (left paren) and before the ending (right paren) brackets.
-
All public members must be placed at the top of the structure, all private members must be placed at the end of the structure.
Each private or public block has the following order of placement of members:- Declaration sub-namespaces.
- Declaration of member variables, uses, typedefs.
- Declaration of functions.
-- end codestruct MyStruct { struct MySubStruct { } using type = float; static constexpr int my_constexpr_var = 4; float m_myVar = 3.14f; void doSomething() { } private: float m_myInternalVariable = 9.8f; void doSomethingInternal() { } };
-
When including a file from a third-party project (for example, a library), use triangular brackets.
When including a file from the current project, use quotation marks. -- code-- end code#include <SomeLibrary/Test.h> #include "MyProject/Test.h"
-
- Do not use 'using namespace' expression.
- Use smart pointers if you expect multiple pointers to an object or if you expect the concept of RAII. Also watch out for circular references when using smart pointers.
- Try to avoid iterating over std::unordered_map, std::map or any other maps.