Does not apply if repository has own coding style
Just drop a Pull Request :)
- Use LF instead of CRLF
- Use spaces, size 4.
Please run make production
before pushing code
- Indent both a case label and the case statement of a switch statement.
Right:
switch (Condition)
{
case 1:
DoSomething();
break;
}
Wrong:
switch (Condition)
{
case 1:
DoSomething();
break;
}
When a function call does not fit onto a line, align arguments like this:
FunctionCall(arg1,
arg2,
arg3);
When making new functions, use an return type. Right:
int func() {}
Wrong:
func() {}
- Do not use spaces around unary operators.
Right: i++
Wrong: i ++
- Place spaces around binary and ternary operators.
Right: a = b + c;
Wrong: a=b+c;
- Do not place spaces before comma and semicolon.
Right:
for (int i = 0; i < 5; i++)
DoSomething();
func1(a, b);
Wrong:
for (int i = 0 ; i < 5 ; i++)
DoSomething();
func1(a , b) ;
- Place spaces between control statements and their parentheses.
Right:
if (Condition)
DoSomething();
Wrong:
if(Condition)
DoSomething();
- Do not place spaces between a function and its parentheses (except for curly parentheses), or between a parenthesis and its content.
Right:
func(a, b);
return { a, b };
Wrong:
func (a, b);
func( a, b );
return {a, b};
- Each statement should get its own line.
Right:
x++;
y++;
if (Condition)
{
DoSomething();
}
Also right but don't use it often
if (Condition) DoSomething();
if (Condition)
DoSomething();
Wrong:
x++; y++;
- Always put braces ({ and }) on their own lines.
- One-line control clauses may use braces, but this is not a requirement. An exception are one-line control clauses including additional comments.
Right:
if (Condition)
DoSomething();
if (Condition)
{
DoSomething();
}
if (Condition)
{
// This is a comment
DoSomething();
}
if (Condition)
DoSomething();
else
DoSomethingElse();
if (Condition)
{
DoSomething();
}
else
{
DoSomethingElse();
YetAnother();
}
Wrong:
if (Condition) {
DoSomething();
}
if (Condition)
// This is a comment
DoSomething();
if (Condition)
DoSomething();
else
{
DoSomethingElse();
YetAnother();
}
- Don’t use inverse logic in control clauses.
Right: if (i == 1)
Wrong: if (1 == i)
- Avoid too many levels of cascaded control structures. Prefer a “linear style” over a “tree style”. Use goto when it helps to make the code cleaner (e.g. for cleanup paths).
Right:
if (!func1())
return;
i = func2();
if (i == 0)
return;
j = func3();
if (j == 1)
return;
…
Wrong:
if (func1())
{
i = func2();
if (func2())
{
j = func3();
if (func3())
{
…
}
}
}
- Function names are lowercase letters.
Right: void func();
Wrong: void Func();
- Name a struct, class, union etc. with cappital letter and variable which lowercase letter
Right:
struct Test
{
int number;
}
Test test;
Wrong:
struct test
{
int Number;
}
test Test;
- Avoid line-wasting comments, which could fit into a single line.
Right:
// This is a one-line comment
/* This is a C-style comment */
//
// This is a comment over multiple lines.
// We don’t define any strict rules for it.
//
Wrong:
//
// This comment wastes two lines
//
- Do not use
LARGE_INTEGER
/ULARGE_INTEGER
unless needed for using APIs. Useint64
/uint64
instead - Use
#pragma once
instead of guard defines in headers