-
Notifications
You must be signed in to change notification settings - Fork 1
Coding Standard
Ivar Jönsson edited this page Sep 20, 2023
·
2 revisions
- Curly brackets should not be on the same line as other text (except for short single-liners in header files, such as getters/setters)
- Opening and closing brackets should be in the same column
- No space between a function's name and parentheses '('
- No space before a comma, semicolon, and parentheses
- Single space before and after binary arithmetic operators
- Single space before and after '?' and ':' in the conditional operator
- No spaces around < and > in template argument lists
- Single space between statements (if, while, for, switch, etc.) and opening '('
- Should always use curly braces unless it improves readability (when having multiple similar-looking statements after each other)
-
elseshould always be on it's own line
- Should be in PascalCase
- Should always have its own column
- Should be in PascalCase
- Should be in PascalCase
- Should be in PascalCase
- Don't use non-size explicit types (uint, int, short, long, etc)
Allowed types:
- uint8_t
- int8_t
- uint16_t
- int16_t
- uint32_t
- int32_t
- uint64_t
- int64_t
- size_t
- float
- double
- Should never use C-style enum, should always use enum class
- Should be PascalCase
- Every enumerate name should be PascalCase and descriptive
Example:
enum class SomeEnum
{
On,
Off,
Invalid
};- Should be PascalCase
- Should start with a verb
- Should be descriptive of what the function does
- Should be camelCase starting with a lowercase character
Example:
void Function()
{
float functionLocalFloat = 0.f;
//...
}- Private/protected non-static member variables should have the prefix m_ and then a camelCase name
- Public non-static member variables should have no prefix (such as in structs)
- Static member variables should have the prefix s_ and then a camelCase name
Example:
class SomeClass
{
private:
float m_floatVariable = 0.f;
uint32_t m_uintVariable = 0;
int32_t s_staticVariable = 0;
};
struct SomeStruct
{
float floatVariable = 0.f;
uint32_t uintVariable = 0;
};- Global variables should have the prefix g_ followed by camelCase
- Static variables should have the prefix s_ followed by camelCase
- Macro names and compile-time constants should be all uppercase separated by an '_'
Example:
int g_globalVariable;
static int s_staticVariable;