Mira Groupware Coding Standards

Overview

  • This document is written for Mira Groupware developers to follow when it comes to coding style. Different developer has a different coding style. We understand having too many rules will became hard to follow and maintain; therefore Mira Groupware Coding Standards will be kept at minimum but will be enough to aid code readability.
  • It is important that these coding standards will be enforced and corrected by peer-review of the code.

Rules

  1. CLASS VARIABLE – class member variable defined within a class will begin with “m_”.
    int m_foo; // class member
  2. CONSTANT VARIABLE – constant variable will be written in all uppercase.
    const int FOO = 100; // constant
  3. LOCAL VARIABLE – local variable defined within a function will begin with no prefix.
    int foo = 100; // local variable
  4. STATIC VARIABLE
    • static variable defined within a class will begin with “sm_”.
      static int sm_foo = 100; // static class member
    • static variable defined as a constant will be treated as a constant variable.
      static const int FOO = 100; // static constants
    • static variable defined within a function will begin with no prefix.
      static int foo = 100; // local variable
  5. GLOBAL VARIABLE - global variable is strongly not recommended, and if it unavoidable then it is required to document the intention of using global variable. All global variable will begin with “g_”.
     int g_evil_global=0;
  6. MACROS – all macros must be defined in uppercases. That includes include guards and macros function.
    #define SQUARE(x) (x)*(x)
  7. NAMESPACE – namespace will be defined by following the directory structure. (ex. If your class is stored in /mira-server/networking/asio, then the namespace for that class should be mira-server::networking::asio)
  8. VARIABLE NAME THAT CONTAINS MORE THAN ONE WORD - If a variable name contains more than one word, each word should be seperated by an underscore.
    int num_of_clients;
  9. FUNCTION NAME THAT CONTAINS MORE THAN ONE WORD – If a function name contains more than one word, each word should be separated by an underscore.
    void set_name();
  10. CLASS VARIABLE MUST DECLARED AS PRIVATE – all class variable must declared as private. If it must be access by other classes, then create a getter and a setter function.
  11. CLASS NAME AND TYPEDEF – All class name and typedef will begin in uppercase.
    class DirectoryBase;
    typedef std::list<std::string> StringList;
    
  12. INDENTATIONS - 4 spaces per level, no tabs in source file
  13. CODE COMMENTING – try your best and provide comment on your code to aid reviewer to understand your intention. Remember that good choice of variable and function names may eliminate the need for comments. Make sure that when you change the code you check the comments; comments not matching code is worse than no comments at all.
  14. DOXYGEN - please review the Doxygen Guidelines since this tools will be used to generate documentation.

References

 
development/coding_standards.txt · Last modified: 2007/09/04 17:00 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki