Code convention
Naming
- Namespaces: snake_case
- Classes: snake_case
- Class members:
m_
prefixed snake_case - Class member getters: class_member name without the
m_
prefix - Interfaces =>
I_
prefixed snake_case - Files
- source:
snake_case.cc
- header:
snake_case.hh
- source:
Structure
- Each directory is compiled as a separate library which gets included from higher level client code
Classes
-
Class definitions follow this structure:
/** * Brief description * ... */ class example_class { private: /// Info about `m_field1` type m_field1; /// Info about `m_field2` type m_field2; public: /// /// Constructors and destructors /// public: /// /// API /// /* * @brief ... * @note ... * @param [in|out] param ... * @return ... */ type do_something1(type param); /* * @brief ... * @note ... * @param [in|out] param1 ... * @param [in|out] param2 ... * @return ... */ type do_something2(type param1, type param2); public: /// /// Getters (optionally also setters) /// type field1() const noexcept { return m_field1; } ... };
### Includes
- Include order is the following:
- Standard library
- Other external libraries
- Local libraries
- Local headers
-
Additional: New line between each category may improve clarity :)
Example
#include <algorithm> #include <boost/...> #include <local_lib/...> #include <blah.hh>
Misc
- Prefer initializing with
{}
over()
- Example
blah b{blah_blah};
- Example
- When using the syntax_analyzer namespace, prefer
syntax_analyzer
oversa
- Use
sa
only when the statement is too long, for example:std::variant<sa::I_statement, sa::function, sa::identifier, sa::I_expression, sa::invalid> m_field;
- Do prefer
syntax_analyzer
for situations like: ```cpp syntax_analyzer::parsing_context &ctx;
- Use