This is style guide for RAPP-API contributors.
You should use it for any new code that you would add to this project and try to format existing code to use this style.
-
RAPP-API uses the Allman/BSD style of indentation.
-
Indent with spaces, not tabs.
-
Use 4 spaces per indent (unless needed like
Makefile
). -
Opening curly bracket is on the following line:
// ✔: struct name { // code }; void func() { // code } if (...) { // code } // ✗: void func() { // code }
-
Put space after
if
,while
andfor
before conditions.// ✔: if () {} // ✗: if() {}
-
Put spaces before and after operators excluding increment and decrement;
// ✔: int a = 1 + 2 * 3; a++; // ✗: int a=1+2*3; a ++;
-
Never put spaces between function name and parameters list.
// ✔: func(args); // ✗: func (args);
-
Never put spaces after
(
and before)
. -
Always put space after comma and semicolon.
// ✔: func(arg1, arg2); for (int i = 0; i < LENGTH; i++) {} // ✗: func(arg1,arg2); for (int i = 0;i<LENGTH;i++) {}
-
Function Declaration parameters should be aligned into new lines
// ✔: func( param1, param2, param3 ); // ✗: func(param1, param2, param3);
-
Calling Functions with multiple parameters that would extend the line in width, should be broken into new lines where and when possible:
// ✔: func(param1, param2, func2(param3, param4), param5); // ✗: func(param1, param2, func2(param3, param4), param5);
-
Naming class members which are private should follow an underscore: The only excpetion to this rule is
struct
where the member is public.// ✔: class foo { private: int var_; }; // ✗: class foo { private: int var; };
Document your code using Doxygen.
-
Documentation comment should use double star notation or tripple slash:
// ✔: /// Some var int var; /** * Some func */ void func();
-
Use slash as tag mark:
// ✔: /** * \param a an integer argument. * \param s a constant character pointer. * \return The results */ int foo(int a, const char *s);
All names in code should be small_snake_case
. No Hungarian notation is used.
Classes and structs names should not have capital letters.
Use namespaces (in C++) and class modules (in Node.JS).
-
Use a class directory for each class file. For example, class
foo
should be infoo/foo.hpp
. -
Use the same name for both definition headers and implementation files. Do not break up the definition and implementation files into different locations.
foo/foo.hpp
foo/foo.cpp
-
Use only internal headers (
.ihh
) for including files.foo/includes.ihh
-
Only include what is absolutely necessary, minimising dependencies.
-
Do not polute the namespace or class definitions with various
#include
/require
, put all of them within your internal include header (includes.ihh
/includes.js
).