Skip to content

Commit

Permalink
Update coding conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Sep 26, 2014
1 parent 1fd6ffc commit 3fceb1e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions doc/procedures/cpp_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ if the case is one line, then one space after ':':
BAD
switch (vendor)
{
case Vendor::Intel:
case Vendor::Intel :
...
case Vendor::AMD:
case Vendor::AMD :
...
}
GOOD
Expand Down Expand Up @@ -348,6 +348,18 @@ not before.
i--;
j++;

Put one space before and after comparison operators:
BAD
if (i==0)
return;
if (j>0)
i = 1;
GOOD
if (i == 0)
return;
if (j > 0)
i = 1;

Don't increment, set or change value of variable inside a function call:
BAD
CalcXY(i++, 2);
Expand Down Expand Up @@ -451,12 +463,12 @@ comparing, if they return true or false.
if (cl)
Disconnect(cl);

When allocating a structure on stack, use = {0} unstead of memset:
When allocating a structure on stack, use zero initializer unstead of memset:
BAD
ShaderParams params;
memset(&params, sizeof(params), 0);
GOOD
ShaderParams params = {0};
ShaderParams params = {};

When possible, prefer inline functions to macros:
BAD
Expand All @@ -465,7 +477,7 @@ When possible, prefer inline functions to macros:
template <typename T>
T RadiansToDegrees(T angle)
{
return angle * 180 / PI;
return angle*180/PI;
}

Macro names should normally be all upper case, with normal spacing as rest of
Expand Down Expand Up @@ -787,11 +799,11 @@ Trivial + - * / expressions should not have spaces around them:
GOOD
Foo((a+b)/(1000*1000));
BAD
Foo((Min(aMin, bMin)+Max(aMax, bMax))*(width*Pow(a, p))/(1000*1000));
Foo((Min(aMin, bMin)+Max(aMax, bMax))*(width+Pow(a, p))/(1000*1000));
GOOD
Foo((Min(aMin, bMin)+Max(aMax, bMax)) * (width*Pow(a, p)) / (1000*1000));
Foo((Min(aMin, bMin)+Max(aMax, bMax)) * (width+Pow(a, p)) / (1000*1000));

Dont put empty lines between code inside functions. If you want to separate
Don't put empty lines between code inside functions. If you want to separate
code fragments, put a comment line.
BAD
for (auto& item : items)
Expand Down

0 comments on commit 3fceb1e

Please sign in to comment.