Outils pour utilisateurs

Outils du site


fr:devel:coding-style

Convention de codage Actionaz

Version 1.0 - By Jonathan Mercier-Ganady

Avant de contribuer au projet, veuillez prendre connaissance de cette page.

La convention utilisée par Actionaz est très semblable à la convention de codage Qt.

Seules les différences avec le standard Qt sont décrits dans cette page.

Règles générales

  1. Ne pas oublier tr() autour des chaînes concernées par la traduction.
  2. Commiter souvent.
  3. Coder en C++, pas en C.
  4. Ne jamais dupliquer du code, c'est le signe d'un code peu efficient : si le cas se produit, prenez l'air et repensez la structure de votre code.
  5. Adaptez vous au projet auquel vous contribuez.

Commentaires

[A traduire]

Only comment when needed, usually naming the variables, classes and methods correctly should be sufficient for every developer to understand what the code does.

  1. Comment each complex algorithm.
  2. Don't over-comment.
    // Wrong
    // Returns: the value of X
    int getX();

Attributs de classe

[A traduire]

  1. Class attributes are always private, use getters and setters to access them.
  2. Class attributes start with a lower m.
    class MyClass
    {
        private:
        int mMyValue;
    };

Méthodes d'affectation et de récupération des attributs

[NdT] les mots getter et setter ont été conservés

[A traduire]

  1. Setters start with “set”.
  2. Getters don't start with “get”.
  3. Getters are const.
    class MyClass
    {
        public:
            int myValue() const { return mMyValue; }
            void setMyValue (int myValue) { mMyValue = myValue; }
        private:
            int mMyValue;
    };

Indentation

[A traduire]

  1. 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.
  2. The tabulation and the indentation size should be set to 4, warning : this is not the default setting in QtCreator !

Declaration de variables

[A traduire]

  1. 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...
    }
  2. Classes doesn't start with any special letter.

Accolades

[A traduire]

  1. The correct way to write an if statement :
    //Correct
    if(foo)
    {
        // do stuff here
    }
    
    //Wrong
    if (foo) {
        // do stuff here
    }
  2. 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() ;
    }
  3. Never use C-style casts.
    // Wrong
    float a = 4.2f;
    int b = (int)a;
    
    // Correct
    float a = 4.2f;
    int b = static_cast<int>(a);

Blocs liés à une instructtion switch

[A traduire]

  1. 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

[A traduire]

  1. No numerical limit to the length of a line, just keep it not “too long”.

Retour à la page : Contribuer à Actionaz

Autres langages pour cette page : (en)

fr/devel/coding-style.txt · Dernière modification : 2021/02/13 11:23 de 127.0.0.1