You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The most important rule is that new code should be consistent with the existing code around it. The rules below illustrate the preferred style when cleaning up existing inconsistently-styled code.
These rules are a work in progress and are subject to additions. Changes to the style can be made with a pull request implementing the change across the entire repository.
Structs & Classes
struct FooBar
{
};
Functions
int *fooBar(const int &x, int *y, int z)
{
*y = x + z;
return y;
}
Variables
int x = 2;
int *y = &x;
int &z = x;
Loops and Conditionals
Single-statement
for (int i=start; i<end; i++)
foo();
Multiple-statement
for (int i=start; i<end; i++) {
foo();
bar();
}
Const
Use const whenever possible.
Static
Use static function declarations whenever possible but static variables sparingly.
Unused variables
int foo(int used, int)
{
// Unused variables are nameless in the function definition
return used;
}