development:player:code-formatting-conventions
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
development:player:code-formatting-conventions [2010/11/08 20:53] – Player2 -> Player fdelapena | development:player:code-formatting-conventions [2015/10/03 09:54] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Code Formatting Conventions===== | =====Code Formatting Conventions===== | ||
- | '' | ||
===Common Sense=== | ===Common Sense=== | ||
Line 16: | Line 15: | ||
Braces in your code should look like the following example: | Braces in your code should look like the following example: | ||
- | < | + | < |
[...] | [...] | ||
} | } | ||
Line 32: | Line 31: | ||
===Whitespaces=== | ===Whitespaces=== | ||
---- | ---- | ||
+ | In no case there should be two whitespaces together. If you want align some code use tabs instead, that are easier to maintain. Pay attention to spaces or tabs at the ending of a line, remove them. | ||
+ | |||
==Conventional operators surrounded by a space character== | ==Conventional operators surrounded by a space character== | ||
- | < | + | < |
==C++ reserved words separated from opening parentheses by a white space== | ==C++ reserved words separated from opening parentheses by a white space== | ||
- | < | + | < |
==Commas followed by a white space== | ==Commas followed by a white space== | ||
- | < | + | < |
- | < | + | < |
==Semicolons followed by a space character, if there is more on a line== | ==Semicolons followed by a space character, if there is more on a line== | ||
- | < | + | < |
- | < | + | < |
==When declaring class inheritance and in a ? construct, colons should be surrounded by white space== | ==When declaring class inheritance and in a ? construct, colons should be surrounded by white space== | ||
- | < | + | < |
- | < | + | < |
==Array delete operator has no whitespace before []== | ==Array delete operator has no whitespace before []== | ||
- | < | + | < |
==STD library and <>== | ==STD library and <>== | ||
No whitespaces before or after <, and whitespaces only after >. | No whitespaces before or after <, and whitespaces only after >. | ||
- | < | + | < |
- | < | + | < |
==Operator overloading== | ==Operator overloading== | ||
Operator keyword is not separated from the name, except for type conversion operators where it is required. | Operator keyword is not separated from the name, except for type conversion operators where it is required. | ||
- | < | + | < |
void operator()() { | void operator()() { | ||
// ... | // ... | ||
Line 71: | Line 72: | ||
==Pointers and casts== | ==Pointers and casts== | ||
- | No whitespace after a cast; and in a pointer, we write a whitespace after it but no before it. Consider " | + | No whitespace after a cast; and in a pointer, we write a whitespace after it but not before it. Consider " |
- | < | + | < |
==References== | ==References== | ||
Unlike pointers, use a whitespace before the "&" | Unlike pointers, use a whitespace before the "&" | ||
- | < | + | < |
int &ref = i;</ | int &ref = i;</ | ||
- | < | + | < |
====Switch / Case constructs==== | ====Switch / Case constructs==== | ||
---- | ---- | ||
- | < | + | < |
- | case 0: // New Game | + | case 0: // New Game |
- | CommandNewGame(); | + | CommandNewGame(); |
- | break; | + | break; |
- | case 1: // Load Game | + | case 1: // Load Game |
- | CommandContinue(); | + | CommandContinue(); |
- | break; | + | break; |
- | case 2: // Exit Game | + | case 2: // Exit Game |
- | CommandShutdown(); | + | CommandShutdown(); |
}</ | }</ | ||
Line 97: | Line 98: | ||
==Constants== | ==Constants== | ||
All upper case, with underscores as name separators, but no leading/ | All upper case, with underscores as name separators, but no leading/ | ||
- | < | + | < |
'' | '' | ||
- | < | + | < |
#define _WINDOW_COMMAND_H_</ | #define _WINDOW_COMMAND_H_</ | ||
==Type names== | ==Type names== | ||
We use RPG Maker XP/VX RGSS and scripts as our API base. Normally classes should be named in UpperCamelCase, | We use RPG Maker XP/VX RGSS and scripts as our API base. Normally classes should be named in UpperCamelCase, | ||
- | < | + | < |
class Game_CommonEvent { | class Game_CommonEvent { | ||
class Window_MenuStatus : public Window_Selectable { | class Window_MenuStatus : public Window_Selectable { | ||
Line 111: | Line 112: | ||
==Functions== | ==Functions== | ||
Functions should be UpperCamelCase. | Functions should be UpperCamelCase. | ||
- | < | + | < |
Property methods should start with Get or Set: | Property methods should start with Get or Set: | ||
- | < | + | < |
public: | public: | ||
int GetThatInt() { return that_int; } | int GetThatInt() { return that_int; } | ||
Line 123: | Line 124: | ||
==Variables== | ==Variables== | ||
Variables should be lower case with underscores as word separators. | Variables should be lower case with underscores as word separators. | ||
- | < | + | < |
+ | |||
+ | ====Headers includes==== | ||
+ | ---- | ||
+ | Use the following format: | ||
+ | <code cpp> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | And when possible use the following headers order: | ||
+ | * System headers (e.g. windows.h) | ||
+ | * C headers (e.g. math.h) | ||
+ | * C++ headers (e.g. string) | ||
+ | * system.h | ||
+ | * Current class/ | ||
+ | * Tools headers (e.g. output.h) | ||
+ | * Backend/ | ||
+ | * Engine headers (e.g. game_character.h) | ||
+ | * liblcf headers (e.g. lmu_reader.h) | ||
+ | |||
+ | For each headers group alphabetically sort the includes. | ||
====Comments==== | ====Comments==== | ||
---- | ---- | ||
- | Use < | + | Use < |
==License File Header== | ==License File Header== | ||
Remember to copy (from any other existing file) the license header to all new created files. | Remember to copy (from any other existing file) the license header to all new created files. | ||
- | ==Function Declaration== | + | ==Documentation== |
- | Use Doxygen like documentation, | + | Use Doxygen like documentation, |
- | < | + | < |
- | /// Description of MyFunction. | + | * Description of MyFunction. |
- | /// A more detailed description here. | + | * A more detailed description here. |
- | /// @param var1 this is a description for var1 | + | * @param var1 : this is a description for var1 |
- | /// @param var2 this is a description for var2 | + | * @param var2 : this is a description for var2 |
- | /// @return here goes a description for return value | + | * @return here goes a description for return value |
- | /////////////////////////////////////////////////////////// | + | */ |
virtual int MyFunction(double var1, std::string var2);</ | virtual int MyFunction(double var1, std::string var2);</ | ||
+ | |||
+ | With the exception of getters and setters: | ||
+ | <code cpp>/** @return description of variable */ | ||
+ | int GetVariable(); | ||
+ | |||
+ | /** @param variable : description of variable */ | ||
+ | void SetVariable(int variable);</ | ||
+ | |||
+ | And for variables: | ||
+ | <code cpp>/** Description of example_variable. */ | ||
+ | std::string example_variable;</ | ||
+ | |||
+ | Remember to document only declarations and not implementations, | ||
+ | |||
+ | ==Code descriptions== | ||
+ | We prefer a global function description with Doxygen headers rather than inside the function descriptions. Only when code is really hard to follow, or there is something hardcoded then add some comments explaining the situation. Do not add redundant comments, like actions that should be already understand easily. | ||
+ | |||
+ | ==Special comments== | ||
+ | <code cpp>// TODO: what is left to do | ||
+ | // FIXME: what code and in what circumstances it does not work, and if possible why it does not work well</ |
development/player/code-formatting-conventions.1289249617.txt.gz · Last modified: 2013/06/30 23:47 (external edit)