User Tools

Site Tools


en:devel:coding-style

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:devel:coding-style [2013/02/10 13:58] – created (raw copy) niconilen:devel:coding-style [2021/02/13 11:23] (current) – external edit 127.0.0.1
Line 1: Line 1:
-Actionaz coding style+====== Actionaz coding style ======
  
-Version 1.0 +//Version 1.0 By Jonathan Mercier-Ganady//
-By Jonathan Mercier-Ganady+
  
-Before contributing to the project please read the following document.+Before contributing to the project please read the following page.
  
-The Actionaz coding style is almost the same as the coding style of Qt : +The Actionaz coding style is almost the same as the [[http://qt-project.org/wiki/Qt_Coding_Style|coding style of Qt]].
-http://qt.gitorious.org/qt/pages/QtCodingStyle+
  
-Note : Only the differences with the Qt coding style are shown.+<note tip>Only the differences with the Qt coding style are shown.</note>
  
-General rules+===== General rules =====
  
-Remember to add tr() around text that can be translated. +  - Remember to add //tr()// around text that can be translated. 
-Commit often, syntax when fixing a Redmine declared bug : [explanation] fixes bug #[bug +  Commit often, 
-number here] +  - Syntax when fixing a Redmine declared bug : [explanation] fixes bug #[bug number here] 
-Code in C++, not in C. +  Code in C++, not in C. 
-Never copy & paste code, if you want to do it that means that something is wrong : re-think +  Never copy & paste code, if you want to do it that means that something is wrong : re-think the code structure. 
-the code structure. +  Adapt yourself to the project for which you are developing.
-Adapt yourself to the project for which you are developing.+
  
-• +===== Comments =====
-• +
- +
-• +
-• +
- +
-• +
- +
-Comments+
  
 Only comment when needed, usually naming the variables, classes and methods correctly Only comment when needed, usually naming the variables, classes and methods correctly
 should be sufficient for every developer to understand what the code does. should be sufficient for every developer to understand what the code does.
  
-• +  - Comment each complex algorithm. 
- +  Don't over-comment.<code>
-Comment each complex algorithm. +
- +
-• +
- +
-Don't over-comment. +
- +
-• +
 // Wrong // Wrong
 // Returns: the value of X // Returns: the value of X
 int getX(); int getX();
 +</code>
  
-Class attributes+===== Class attributes =====
  
-Class attributes are always private, use getters and setters to access them. 
- 
- 
- 
-Class attributes start with a lower m. 
- 
- 
  
 +  - Class attributes are always private, use getters and setters to access them.
 +  - Class attributes start with a lower m.<code>
 class MyClass class MyClass
 { {
-private: +    private: 
-int mMyValue;+    int mMyValue;
 }; };
 +</code>
  
-Setters and getters +===== Setters and getters =====
- +
-Setters start with “set”. +
- +
-• +
- +
-Getters don't start with “get”. +
- +
-• +
- +
-Getters are const. +
- +
-+
  
 +  - Setters start with “set”.
 +  - Getters don't start with “get”.
 +  - Getters are const.<code>
 class MyClass class MyClass
 { {
-public: +    public: 
-int myValue() const +        int myValue() const { return mMyValue; } 
-{ return mMyValue; } +        void setMyValue (int myValue) { mMyValue = myValue; } 
-void setMyValue (int myValue) { mMyValue = myValue; } +    private: 
-private: +        int mMyValue;
-int mMyValue;+
 }; };
 +</code>
  
-Indentation+===== Indentation =====
  
-Indentation is made with tabulations, not spaces. The tabulation character is designed for +  - Indentation is made with tabulations, not spaces. The tabulation character is designed for that. Spaces are made to separate words, so using spaces to indent in 2010+ with modern editors makes no sense. 
-that. Spaces are made to separate words, so using spaces to indent in 2010+ with modern +  - The tabulation and the indentation size should be set to <wrap hi>**4**</wrap>, warning : this is not the default setting in QtCreator !
-editors makes no sense.+
  
-• +===== Declaring variables =====
- +
-The tabulation and the indentation size should be set to 4, warning : this is not the default +
-setting in QtCreator ! +
- +
-• +
- +
-Declaring variables +
- +
-Variables are declared when used, not at the start of a block like in C. +
- +
-+
  
 +  - Classes doesn't start with any special letter.
 +  - Variables are declared when used, not at the start of a block like in C.<code>
 // Wrong // Wrong
 int actionIndex; int actionIndex;
Line 112: Line 71:
 for(int i = 0; i < 5; ++i) for(int i = 0; i < 5; ++i)
 { {
-actionIndex = i * 2; +    actionIndex = i * 2; 
- +    // actionIndex is used here...
-// actionIndex is used here... +
 } }
  
Line 121: Line 78:
 for(int i = 0; i < 5; ++i) for(int i = 0; i < 5; ++i)
 { {
-int actionIndex = i * 2; +    int actionIndex = i * 2; 
- +    // actionIndex is used here...
-// actionIndex is used here... +
 } }
 +</code>
  
-Classes doesn't start with any special letter. +===== Braces =====
- +
-• +
- +
-Braces +
- +
-The correct way to write an if statement : +
- +
-+
  
 +  - The correct way to write an if statement :<code>
 +//Correct
 if(foo) if(foo)
 { {
-// do stuff here+    // do stuff here
 } }
-So please, never use the following notation : 
  
 +//Wrong
 if (foo) { if (foo) {
-// do stuff here +    // do stuff here
 } }
 +</code>
 +  - The following notation is accepted when the statement is not too complex, and for one level only.<code>
 +//Wrong
 +if(foo)
 +    if(bar)
 +        doSomething();
  
-The following notation is accepted when the statement is not too complex, and for one level +//Correct
-only. +
- +
-• +
- +
-// Wrong +
-if(foo) +
-if(bar) +
-doSomething() ; +
-// Correct+
 if(foo) if(foo)
 { {
-if(bar) +    if(bar) 
-doSomething() ;+        doSomething();
 } }
-• Never use C-style casts. +</code> 
 +  - Never use C-style casts.<code>
 // Wrong // Wrong
 float a = 4.2f; float a = 4.2f;
 int b = (int)a; int b = (int)a;
 +
 // Correct // Correct
 float a = 4.2f; float a = 4.2f;
 int b = static_cast<int>(a); int b = static_cast<int>(a);
 +</code>
 +
 +===== 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
  
-Switch statements+===== Line breaks =====
  
-Every case does not have to have a break (or return) statement at the end or comment to +  - No numerical limit to the length of line, just keep it not “too long”.
-indicate that there’s intentionally no break+
  
-+---- 
 +Go back to the page : [[en:devel|Contribute to Actionaz]]
  
-Line breaks+Other languages for this page : [[fr:devel:coding-style|(fr)]] 
  
-No numerical limit to the length of a line, just keep it not “too long”. 
  
- 
en/devel/coding-style.1360504699.txt.gz · Last modified: 2021/02/13 11:23 (external edit)