-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Conventions
Sebastian edited this page Oct 18, 2023
·
2 revisions
First, some general bits and bobs:
- Use names that describe the purpose or intent of the object.
- Write abbreviations as one word, e.g.
myUrlVariableorstartRpc()orUrlType - Do not use exceptions; document failure values in function returns
-
camelCasefor functions, e.g.myAwesomeFunction() -
camelCasefor function variables, e.g.myAwesomeVariable -
camelCase_for class member variables, e.g.myAwesomeMemberVariable_ -
CONSTANT_CASEfor constants, e.g.MY_AWESOME_CONSTANT -
PascalCasefor type names, e.g.MyAwesomeType
- Comment code where the intent is unclear, e.g. an obscure hack that’s not well-documented
- Include Doxygen comments in header files along with function definitions
- As a general rule, make it so that your code requires as little comments as possible
- All header files should start with
#pragma once - All dependencies should be directly included (no transitive dependencies)
-
Example: if
ClassA.hincludesClassB.hand uses a file included inClassB.h, that include should also be present inClassA.h
-
Example: if
- Avoid forward declaration where possible
- DO: use forward declaration for a circular dependency
- DO NOT: use forward declaration to hide a dependency
- Inline functions defined in the header should be 5 lines or less
- DO: inline getters, setters and other one-liners
- DO NOT: shove complex behavior into the header file
- Do not use
using namespace xxxin header files (e.g.using namespace std)
- Static functions should be placed in a separate namespace, as opposed to in class definitions
- Only use a static class function where the function is tightly bound to the class
- Each class has their own header (.h) and implementation file (.cpp)
- Header-only classes do not need a corresponding .cpp file
- Files are named after the class they implement (e.g.
Burgeris implemented inBurger.handBurger.cpp)