2 KiB
Style guide
This is style guide for fish 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.
Formatting
-
fish 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++) {}
Documentation
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);
Naming
All names in code should be small_snake_case
. No Hungarian notation is used.
Classes and structs names should be followed by _t
.