Awesome
Plume C++ Style Guide
<p align="center"> <img src="https://github.com/mwalczyk/plume/blob/master/logo.svg" alt="plume logo" width="400" height="auto"/> </p>Naming Conventions
Class and struct names should be CamelCase
.
Variable and function names should be all lowercase and separated by underscores (ex. int number_of_wheels
).
In addition, the following prefixes should be used:
m_
for member variabless_
for static variablesg_
for global variables
Note that function parameters have no special prefix.
Use ALL_CAPS
for macro and enum
fields only - not constants.
Example:
enum class ErrorCode
{
ERROR_OUT_OF_MEMORY,
ERROR_BAD_PATH,
// ...
}
Namespaces should also be all lowercase and separated by underscores (ex. namespace graphics
).
Modifiers
Reference and pointer modifiers (&
and *
) always appear closest to the type.
Examples:
// Free-standing variables
T* ptr;
// Function return types
T& operator[](size_t index);
// Function parameters
void set_value(T& value);
Curly Braces
Always place curly braces on newlines. This includes:
- Class / struct declarations
- If-else blocks
- Try-catch statements
- Switch statements
- Function definitions
- Etc.
Example:
if (condition)
{
// ...
}
Comments
Use doxygen style //!
comments above class and function declarations to describe their
intended purpose / functionality.
Otherwise, use the standard //
comment notation. Do not use /* */
for multi-line comments.
Class Structure
Use the public
before protected
before private
order.
Within each block, items should appear in the following order:
using
declarations andtypedef
s- Static functions
- Constructors
- Destructors
- Member functions
- Static variables
- Member variables
friend
declarations