Mudita adopts the C++ Core Guidelines document, which is an open-source project to maintain modern authoritative guidelines for writing C++ code using the current C++ Standard. See http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.
The Mudita C++ Coding Guidelines document is just an update to the C++ Core Guidelines. It adds new rules and exceptions to existing ones.
All the C++ Core Guidelines rules are defined in the following document: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.
All the C++ Core Guidelines rules are adopted to the Mudita C++ Core Guidelines.
Mudita rules override and add exceptions to the C++ Core Guidelines ruleset.
See: Motivation
The includes shall be sorted in the following order:
Example:
// file: module-gui/gui/widgets/Item.cpp
#include "Item.hpp" // Header that corresponds to this .cpp file
#include "Alignment.hpp" // Header from a current directory
#include <gui/Common.hpp> // Header from the same module
#include <Timers/Timer.hpp> // Header from other module
#include <sml/include/boost/sml.hpp> // Header from 3rd-party module
#include <cstdint> // Header from the standard library
The current std::to_string() implementation from the stdlib used in the MuditaOS doesn't handle 64bit numeric values properly. Use of utils::to_string is therefore recommended.
Prefer enum / struct params over bool, e.g.:
enum E { False, True };
See: Motivation
If it is justified to use such values, use externally linked, compile-time initiated values with automatic type resolution, e.g.:
constexpr inline auto someString = "a string";
constexpr inline auto someValue = 10U;
instead of
const inline std::string someString = "a string";
const inline unsigned someValue = 10;
class Foo {
private:
static constexpr auto someString = "a string";
};
Both upper- and lower-case of TODO, FIXME, etc. are prohibited.
Doxygen comments shall not state the obvious. Don't literally describe what code does, unless the behaviour is non-obvious to a reader who understands C++ well.
Note: Don’t document implementations if declarations have been already documented.