-
Notifications
You must be signed in to change notification settings - Fork 46
Coding convention
When grouping variables, numbers and operators, seperate them with spaces instead of compressing it into an unreadable text block. Where it leads to better understanding, also seperate brackets. In some cases the compact style is preferred. Simply make the code as easy to read as possible! good:
a = b + c * 5 - d; a = b + (c * 5) - d; x = sqrt(a*a + b*b + c*c); // <- better understandable if not spaced y = ( ((100 * x / c) + ((a - c) / 16)) * 0.125f < 100) ? true : false;
bad:
a = b+c*5-d; y=(((100*x/c)+((a-c)/16))*0.125f<100)?true:false;
Use 4 spaces instead of tabs in any intendation. Use intendation instead of clamping a statement behind a conditional expression. Exceptions are made where it improves readability (multiple ifs of the same type or one-line inline functions in .h files).
good:
if(a == b)
....printf("\n");
bad:
if(a == b)
>> printf("\n");
if(a == b) printf("\n");
Use curly brackets only after a newline:
good:
for(a = 0; a < 10; a++)
{
printf("%u\n",a);
}
bad:
for(a = 0; a < 10; a++){
printf("%u\n",a);
}
Class or struct names start with capital letters. Class functions should be CamelCased, but start with capital letters:
good:
class HolyShitMaker
{
void MakeShit();
bool Clone();
}
bad:
class holyShitMaker
{
void make_shit();
bool clone();
}
Private class members should start with an underscore.
Please note that these are only guidelines and in no way obligating, and it happens often enough that older code does not meet them. When posting patches or committing code to the SVN, it is appreciated (and nice of you) if you follow the guidelines - What matters in the end is that the code is readable and understandable.
Anything not described above is up to you; as an orientation refer to the code already existing.