fr:devel:coding-style
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| fr:devel:coding-style [2013/02/10 13:57] – créée (copie brute) niconil | fr:devel:coding-style [2021/02/13 11:23] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | Actionaz | + | ====== Convention de codage |
| - | Version 1.0 | + | //Version 1.0 - By Jonathan Mercier-Ganady// |
| - | By Jonathan Mercier-Ganady | + | |
| - | Before contributing to the project please read the following document. | + | Avant de contribuer au projet, veuillez prendre connaissance de cette page. |
| - | The Actionaz | + | La convention utilisée par Actionaz |
| - | http://qt.gitorious.org/qt/pages/ | + | |
| - | Note : Only the differences with the Qt coding style are shown. | + | <note tip> |
| - | General rules | + | ===== Règles générales ===== |
| - | Remember to add tr() around text that can be translated. | + | - Ne pas oublier //tr()// autour des chaînes concernées par la traduction. |
| - | Commit often, syntax when fixing a Redmine declared bug : [explanation] fixes bug #[bug | + | - Commiter souvent. |
| - | number here] | + | - Coder en C++, pas en C. |
| - | Code in C++, not in C. | + | - Ne jamais dupliquer du code, c'est le signe d' |
| - | Never copy & paste code, if you want to do it that means that something is wrong : re-think | + | - Adaptez vous au projet auquel vous contribuez. |
| - | the code structure. | + | |
| - | Adapt yourself to the project for which you are developing. | + | |
| - | • | + | ===== Commentaires ===== |
| - | • | + | |
| - | • | + | //[A traduire]// |
| - | • | + | |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | 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. |
| - | + | | |
| - | Comment each complex algorithm. | + | |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Don't over-comment. | + | |
| - | + | ||
| - | • | + | |
| // Wrong | // Wrong | ||
| // Returns: the value of X | // Returns: the value of X | ||
| int getX(); | int getX(); | ||
| + | </ | ||
| - | Class attributes | + | ===== Attributs de classe ===== |
| - | + | ||
| - | Class attributes are always private, use getters and setters to access them. | + | |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Class attributes start with a lower m. | + | |
| - | + | ||
| - | • | + | |
| + | //[A traduire]// | ||
| + | - Class attributes are always private, use getters and setters to access them. | ||
| + | - Class attributes start with a lower m.< | ||
| class MyClass | class MyClass | ||
| { | { | ||
| - | private: | + | |
| - | int mMyValue; | + | int mMyValue; |
| }; | }; | ||
| + | </ | ||
| - | Setters and getters | + | ===== Méthodes d' |
| - | Setters start with “set”. | + | [NdT] les mots //getter// et //setter// ont été conservés |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Getters don't start with “get”. | + | |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Getters are const. | + | |
| - | + | ||
| - | • | + | |
| + | //[A traduire]// | ||
| + | - Setters start with “set”. | ||
| + | - Getters don't start with “get”. | ||
| + | - Getters are const.< | ||
| class MyClass | class MyClass | ||
| { | { | ||
| - | 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; | + | |
| }; | }; | ||
| + | </ | ||
| - | Indentation | + | ===== Indentation |
| - | Indentation is made with tabulations, | + | //[A traduire]// |
| - | that. Spaces are made to separate words, so using spaces to indent in 2010+ with modern | + | - Indentation is made with tabulations, |
| - | editors makes no sense. | + | - The tabulation and the indentation size should be set to <wrap hi> |
| - | • | + | ===== Declaration de variables |
| - | + | ||
| - | The tabulation and the indentation size should be set to 4, warning : this is not the default | + | |
| - | setting in QtCreator ! | + | |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Declaring | + | |
| - | + | ||
| - | Variables are declared when used, not at the start of a block like in C. | + | |
| - | + | ||
| - | • | + | |
| + | //[A traduire]// | ||
| + | - Variables are declared when used, not at the start of a block like in C.< | ||
| // Wrong | // Wrong | ||
| int actionIndex; | int actionIndex; | ||
| Ligne 112: | Ligne 76: | ||
| for(int i = 0; i < 5; ++i) | for(int i = 0; i < 5; ++i) | ||
| { | { | ||
| - | actionIndex = i * 2; | + | |
| - | + | // actionIndex is used here... | |
| - | // actionIndex is used here... | + | |
| } | } | ||
| Ligne 121: | Ligne 83: | ||
| for(int i = 0; i < 5; ++i) | for(int i = 0; i < 5; ++i) | ||
| { | { | ||
| - | int actionIndex = i * 2; | + | |
| - | + | // actionIndex is used here... | |
| - | // actionIndex is used here... | + | |
| } | } | ||
| + | </ | ||
| + | - Classes doesn' | ||
| - | Classes doesn' | + | ===== Accolades ===== |
| - | + | ||
| - | • | + | |
| - | + | ||
| - | Braces | + | |
| - | + | ||
| - | The correct way to write an if statement : | + | |
| - | + | ||
| - | • | + | |
| + | //[A traduire]// | ||
| + | - The correct way to write an if statement :< | ||
| + | //Correct | ||
| if(foo) | if(foo) | ||
| { | { | ||
| - | // do stuff here | + | |
| } | } | ||
| - | So please, never use the following notation : | ||
| + | //Wrong | ||
| if (foo) { | 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() ; | ||
| - | 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) | + | |
| - | doSomething() ; | + | doSomething() ; |
| } | } | ||
| - | • Never use C-style casts. | + | </ |
| + | - Never use C-style casts.< | ||
| // 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 b = static_cast< | ||
| + | </ | ||
| - | Switch statements | + | ===== Blocs liés à une instructtion switch ===== |
| - | Every case does not have to have a break (or return) statement at the end or a comment to | + | //[A traduire]// |
| - | indicate that there’s intentionally no break | + | - 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 |
| - | • | + | ===== Retour à la ligne ===== |
| - | Line breaks | + | //[A traduire]// |
| + | - No numerical limit to the length of a line, just keep it not “too long”. | ||
| - | No numerical limit to the length of a line, just keep it not “too long”. | + | ---- |
| + | Retour à la page : [[fr: | ||
| - | • | + | Autres langages pour cette page : [[en: |
fr/devel/coding-style.1360504662.txt.gz · Dernière modification : (modification externe)
