en:devel:coding-style
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | en:devel:coding-style [2021/02/13 11:23] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Actionaz coding style ====== | ||
+ | |||
+ | //Version 1.0 - By Jonathan Mercier-Ganady// | ||
+ | |||
+ | Before contributing to the project please read the following page. | ||
+ | |||
+ | The Actionaz coding style is almost the same as the [[http:// | ||
+ | |||
+ | <note tip>Only the differences with the Qt coding style are shown.</ | ||
+ | |||
+ | ===== General rules ===== | ||
+ | |||
+ | - Remember to add //tr()// around text that can be translated. | ||
+ | - Commit often, | ||
+ | - Syntax when fixing a Redmine declared bug : [explanation] fixes bug #[bug number here] | ||
+ | - Code in C++, not in C. | ||
+ | - Never copy & paste code, if you want to do it that means that something is wrong : re-think the code structure. | ||
+ | - Adapt yourself to the project for which you are developing. | ||
+ | |||
+ | ===== Comments ===== | ||
+ | |||
+ | Only comment when needed, usually naming the variables, classes and methods correctly | ||
+ | should be sufficient for every developer to understand what the code does. | ||
+ | |||
+ | - Comment each complex algorithm. | ||
+ | - Don't over-comment.< | ||
+ | // Wrong | ||
+ | // Returns: the value of X | ||
+ | int getX(); | ||
+ | </ | ||
+ | |||
+ | ===== Class attributes ===== | ||
+ | |||
+ | |||
+ | - Class attributes are always private, use getters and setters to access them. | ||
+ | - Class attributes start with a lower m.< | ||
+ | class MyClass | ||
+ | { | ||
+ | private: | ||
+ | int mMyValue; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ===== Setters and getters ===== | ||
+ | |||
+ | - Setters start with “set”. | ||
+ | - Getters don't start with “get”. | ||
+ | - Getters are const.< | ||
+ | class MyClass | ||
+ | { | ||
+ | public: | ||
+ | int myValue() const { return mMyValue; } | ||
+ | void setMyValue (int myValue) { mMyValue = myValue; } | ||
+ | private: | ||
+ | int mMyValue; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ===== Indentation ===== | ||
+ | |||
+ | - Indentation is made with tabulations, | ||
+ | - The tabulation and the indentation size should be set to <wrap hi> | ||
+ | |||
+ | ===== Declaring variables ===== | ||
+ | |||
+ | - Classes doesn' | ||
+ | - Variables are declared when used, not at the start of a block like in C.< | ||
+ | // Wrong | ||
+ | int actionIndex; | ||
+ | |||
+ | for(int i = 0; i < 5; ++i) | ||
+ | { | ||
+ | actionIndex = i * 2; | ||
+ | // actionIndex is used here... | ||
+ | } | ||
+ | |||
+ | // Correct | ||
+ | for(int i = 0; i < 5; ++i) | ||
+ | { | ||
+ | int actionIndex = i * 2; | ||
+ | // actionIndex is used here... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Braces ===== | ||
+ | |||
+ | - The correct way to write an if statement :< | ||
+ | //Correct | ||
+ | if(foo) | ||
+ | { | ||
+ | // do stuff here | ||
+ | } | ||
+ | |||
+ | //Wrong | ||
+ | if (foo) { | ||
+ | // do stuff here | ||
+ | } | ||
+ | </ | ||
+ | - The following notation is accepted when the statement is not too complex, and for one level only.< | ||
+ | //Wrong | ||
+ | if(foo) | ||
+ | if(bar) | ||
+ | doSomething(); | ||
+ | |||
+ | //Correct | ||
+ | if(foo) | ||
+ | { | ||
+ | if(bar) | ||
+ | doSomething(); | ||
+ | } | ||
+ | </ | ||
+ | - Never use C-style casts.< | ||
+ | // Wrong | ||
+ | float a = 4.2f; | ||
+ | int b = (int)a; | ||
+ | |||
+ | // Correct | ||
+ | float a = 4.2f; | ||
+ | int b = static_cast< | ||
+ | </ | ||
+ | |||
+ | ===== Switch statements ===== | ||
+ | |||
+ | - Every case **does not** have to have a break (or return) statement at the end or a comment to indicate that there’s intentionally no break | ||
+ | |||
+ | ===== Line breaks ===== | ||
+ | |||
+ | - No numerical limit to the length of a line, just keep it not “too long”. | ||
+ | |||
+ | ---- | ||
+ | Go back to the page : [[en: | ||
+ | |||
+ | Other languages for this page : [[fr: | ||
+ | |||