Skip to content
CharuChopra84 edited this page Nov 24, 2014 · 9 revisions
  1. Meaningful names of variables, classes and functions:
    The name of any variable, class or function should clearly imply what it does. Assigning a random name to any of these should not be done.

    e.g. myFunctionName() is not a meaningful name.

  2. Spacing:
    Proper indentation and spacing is to be followed.

    • No space should precede the comma.
      e.g.

      int a, b;  // correct  
      int a ,b; // incorrect  
      int a , b; // incorrect 
      
    • While creating conditional blocks, say using if or for etc., a space should be there between the keyword and the opening parenthesis that follows.
      e.g.

      if (condition)  // correct  
      if(condition) // incorrect  
      
      for (int i = 0; i < 10; i++)  // correct  
      for(int i = 0; i < 10; i++) // incorrect  
      
    • Similarly while creating pointers, a space should be there between the class name for which pointer is created and the asterisk symbol.

      e.g. className *classObject; is the correct manner. Anything like the following is incorrect:

      className * classObject,  
      className* classObject 
      
    • Creating a class should look like-

      className : public inheritedClass
      {
        // class definition
      };
      

      Keeping a space before and after the colon is advised.

    • There should be a space before and after each operand.
      e.g.

      x = y + z; // correct
      x = y+z; // incorrect
      

      Note: This is to be done for all the operands.

  3. camel-Casing:
    The naming standard for names to be followed is camel-Casing.
    e.g.

    functionName     
    className  
    variableName  
    

    Any names of the form are not acceptable according to the naming convention:

    functionname  
    function_name  
    _function_name  
    
  4. Character limit in a line:
    The number of characters in a line should not exceed 80.
    Hint: Enable Display right margin at column: 80 under Tools->Options->Text Editor->Display in your Qt IDE.

  5. Declaring functions and variables:
    The functions should be declared together and variables together.
    e.g.

    void function1();  
    void function2(); // functions together
    
    int variable1;  
    int variable2; // variables together
    

    It should not be like:

    void function1();  
    int variable1;  
    void function2();  // functions along with a variable in one block
    
    int variable2; 
    

    Anything of the second form is not recommended to be done.

  6. Defining if-else blocks:
    A line between if and else blocks: An empty line must be there between if and else blocks if each contains multiple statements. Otherwise, this empty line can be avoided.
    e.g.

    if (condition)  
    {    
      /**
      * do something  
      * do more 
      */  
    }  
    
    else  
    {  
      /**
      * do something  
      * do more 
      */  
    }
    

    Or it can be like:

    if (condition)    
      // do something  
    else  
      // do something  
    

    Anything of form other than this is not recommended. It keeps code readability good.

Clone this wiki locally