development:player:code-formatting-conventions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:player:code-formatting-conventions [2011/09/25 16:47] – fdelapena | development:player:code-formatting-conventions [2015/10/03 09:54] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 15: | Line 15: | ||
Braces in your code should look like the following example: | Braces in your code should look like the following example: | ||
- | < | + | < |
[...] | [...] | ||
} | } | ||
Line 34: | Line 34: | ||
==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 73: | Line 73: | ||
==Pointers and casts== | ==Pointers and casts== | ||
No whitespace after a cast; and in a pointer, we write a whitespace after it but not 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(); | ||
Line 98: | 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 112: | 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 124: | 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==== | ====Headers includes==== | ||
---- | ---- | ||
Use the following format: | Use the following format: | ||
- | < | + | < |
- | // Headers | + | |
- | //////////////////////////////////////////////////////////// | + | |
#include " | #include " | ||
#include " | #include " | ||
Line 144: | Line 142: | ||
* Backend/ | * Backend/ | ||
* Engine headers (e.g. game_character.h) | * Engine headers (e.g. game_character.h) | ||
- | * Readers | + | * liblcf |
For each headers group alphabetically sort the includes. | For each headers group alphabetically sort the includes. | ||
Line 157: | Line 155: | ||
==Documentation== | ==Documentation== | ||
Use Doxygen like documentation, | Use Doxygen like documentation, | ||
- | <code cpp>//////////////////////////////////////////////////////////// | + | <code cpp>/** |
- | /// 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: | With the exception of getters and setters: | ||
- | <code cpp>/// @return description of variable | + | <code cpp>/** @return description of variable |
int GetVariable(); | int GetVariable(); | ||
- | /// @param variable : description of variable | + | /** @param variable : description of variable |
void SetVariable(int variable);</ | void SetVariable(int variable);</ | ||
And for variables: | And for variables: | ||
- | <code cpp>/// Description of example_variable. | + | <code cpp>/** Description of example_variable. |
std::string example_variable;</ | std::string example_variable;</ | ||
Remember to document only declarations and not implementations, | Remember to document only declarations and not implementations, | ||
- | |||
- | ==Separators== | ||
- | For organizing better .cpp files add < | ||
==Code descriptions== | ==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 < | + | 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== | ==Special comments== | ||
<code cpp>// TODO: what is left to do | <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</ | // 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.1316969268.txt.gz · Last modified: 2013/06/30 23:47 (external edit)