These guidelines should be followed for all new C++ code in this repository.
The rules are based on some Google style rules.
Reviewers will be enforcing them, so please obey them.
- Use .cpp extension instead of .cc
- Use "#pragma once" instead of #define guard
- No global variables (even const)
- Every .cpp file should have an associated .h file link.
- Guard all headers link.
- Includes order: related header -> C system includes (ABS order) -> C++ system includes (ABS order) -> other includes (ABS order) -> project includes (ABS order) -> conditional includes link.
- In constructors no virtual method calls or functions that can fail and if you can't signal an error link.
- No implicit conversions link.
- Make class data members private, unless they are static const link
- When defining a function, parameter order is: inputs, then outputs link
- All parameters passed to a function by reference must be labeled const link
- Use standard smart pointers when ownership can be transferred link
- Use prefix form (++i) of the increment and decrement operators with iterators and other template objects link
- Use a precise-width integer type from from <stdint.h> for all integer types and size_t and ptrdiff_t when required link
- Use 0 for integers, 0.0 for reals, nullptr for pointers, and '\0' for chars link
- Do not use non-standard extensions (exception: #pragma once) link
- No namespace aliases link
- Filenames should be all lowercase and can include underscores (_) link
- Type names or enumerators start with a capital letter and have a capital letter for each new word, with no underscores ("Camel Case") link
- The names of namespaces, functions/methods, variables (including function parameters), constants and data members are all lowercase, with underscores between words link
- Macros names are uppercase with underscores between the words: THIS_THIS_MY_CONSTANT link
- Each line of text in your code must be at most 120 characters long.
- Do not use any of non-ASCII characters link
- Use spaces, no tabs, and indent 2 spaces at a time link
- Return type on the same line as function name, and its parameters on the same line if they fit link
- Always use braces for: switch-case-blocks, while-loop and for-loop bodies; and no empty bodies for loops link
- No spaces around period or arrow in pointer or reference expression link
- Class sections in public, protected and private order, each indented one space link
- The contents of namespaces are not indented link
- Headers should be self-contained link.
- Use C++-style casts, or brace initialization for conversion of arithmetic types instead of C-like casts link
- Avoid forward declaration where possible link.
- Define inline functions when they are <= 10 lines link.
- Put the code in namespaces with unique names, but never use using directive link
- Put definitions that will not be used outside .cpp in unnamed namespace or declare them static (do not do that in headers) link.
- Place nonmember functions in a namespace link.
- Place a function's variables in the narrowest scope possible, and initialize variables in the declaration link.
- Static storage duration variables are allowed only if declared as constexpr and they are POD link.
- Do not make new classes copyable or movable link
- Prefer classes, not structs link
- Prefer composition on inheritance, but when inherinece is still required, then make it public link
- No multiple inheritance link
- Do not overload operators link
- In a class group similar declarations together, placing public parts earlier [link](Interface class should ha://google.github.io/styleguide/cppguide.html#Declaration_Order)
- No functions body longer than 60 lines, excluding comments and empty lines link
- No friend classes link
- Avoid using Run Time Type Information (RTTI) link
- Use const or constexpr where possible link
- Code should be 64-bit and 32-bit friendly link
- Avoid defining complex macros link
- Use sizeof(varname) instead of sizeof(type) link
- Use auto when it increases readability, but do not initialize an auto-typed variable with a braced initializer list link
- Avoid overcomplicated template programming link
- Do not define specializations of std::hash link
- Use C++11/14 features when needed, but no compile-time rational numbers (<ratio>), no <cfenv> and <fenv.h> headers and no ref-qualifiers on member functions link
- No abbreviations in naming, make the names self-descriptive link
- Use either the // or /* */ comment syntax, as long as you are consistent [link] (https://google.github.io/styleguide/cppguide.html#Comment_Style)
- If a .h declares multiple abstractions, the file-level comment should broadly describe the contents of the file, and how the abstractions are related link
- Every class declaration should have an accompanying comment that describes what it is for and how it should be used link
- Use function-wide comments for non-obvious functions link
- No variable (including function arguments) comments, use self-descriptive variable names instead link
- Add comments for tricky, non-obvious, interesting, or important parts of your code only link
- Pay attention to punctuation, spelling, and grammar in the comments link
- Use TODO or FIXME comments for code that is temporary, a short-term solution link
- Each line of text in your code should be less then 80 characters long link
- Format parameters and bodies of lambdas as for any other function, and capture lists like other comma-separated lists link
- Format a braced initializer list exactly like you would format a function call in its place link
- No spaces inside parentheses with one condition, one space after if, one space after closing paranthes, and put the if and else keywords on separate lines link
- No multiple variables in one declaration if those have pointer or reference decorations link
- When break long boolean expressions then put boolean operator at the end of the line link
- Never put trailing whitespaces at the end of a line link
- Do not use C++ exceptions is possible link
In all other cases use common sense and be consistent.