This coding standard is based on google c++ coding standard(https://google-styleguide.googlecode.com/svn/trunk/cppguide.html)
Use #define guard in all header files. <FILE>_H
format is recommended.
#ifndef FILE_H
#define FILE_H
...
#endif // FILE_H
Inline function is allowed only if it is less than 10 lines.
Input parameters should precede output pamameters.
maximum 80 characters in a line.
2 space indent at a time. Do not use a tab for indentation.
Write a function call all in a line if it fits. If not, break it into multiple lines aligned with the first argument. Do not insert spaces after open paren and before close paren.
int value = foo(arg1, arg2, arg3);
int value = foo(arg1,
arg2,
arg3);
Use named parameters in function declaration.
ReturnType FunctionName(int, char); // not allowed
ReturnType FunctionName(int arg1, char arg2); // Use this
Return type should be on the same line as function name and parameters if it fits. If not, break between them aligned with the first argument.
ReturnType FunctionName(int arg1,
char arg2);
If even first argument does not fit in a line, write it in a new line with 4 space indent.
ReturnType FunctionName(
int arg1,
char arg2);
The open curly brace should be at the same line. The close curly brace should be either at the same line as its open curly brace or at new line.
ReturnType FunctionName(int arg1, char arg2){ };
ReturnType FunctionName(int arg1, char arg2){
...
}
ReturnType FunctionName(int arg1, char arg2)
{ // not allowed
...
}
Use a space between the if and open brace. Open brace on the same line as the if.
if (condition) {
...
}
Short conditional statements may be written in a line unless it has no else part.
if (condition) DoSomething(); // ok
if (condition)
DoSomething(); // ok
Use a space between the switch and loops(for,while,do-while) and open brace. Open brace on the same line as the switch and loops.
while (condition) {
...
}
Single loop body statement may be written without braces.
while (condition) DoSomething(); // ok
for (condition)
DoSomething(); // ok
The open curly brace should be at the same line. Declare public, protect, and private sections in order with 1 space indent.
class MyClass : public ParentClass {
public:
MyClass();
~MyClass();
private:
void DoTheings();
int my_variable;
};
Use UpperCamelCase for class names. No underscore. Type names include classes, structs, typedefs, and enums.
Class MyClassName {
...
}
typedef MyTypeName {
...
}
Use lower cases and underscore for variable names.
int lower_case_variable;
Use a 'k' followed by UpperCamelCase.
#define kConstantUse
Use UpperCamelCase for regular function names. No underscore.
Use lower cases.
Use constant style(a 'k' followed by UpperCamelCase.)
enum MyEnum {
kOK = 0, // OK
kNotOK,
kError,
};
enum MyEnum {
OK = 0, // not allowed
NOT_OK,
ERROR,
};
Always use explicit
keyword when declaring callable constructors.
Use struct when handling data without any operation. Otherwise, use class.
Use either // or /* */ style comments. However, // style is much prefered.
This coding standard is based on google javascript coding standard(https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
Always declare variable before use.
Always use semicolons.
Do not declare functions within a block.
Do not use wrapper objects for primitive types.
Do not use with
statement.
Do not modify prototypes of builtin objects
Use lowerCamelCase for varible names and function names.
var myFirstVariable;
function myFirstFunction {
...
}
Use UpperCamelCase for constructor names
function MyConstructorFunction(input) {
this.variable = input;
...
}
Follow C/C++ formatting above.
The coding conventions for Python code follows PEP 8 - Style Guide for Python Code