SipXtapi coding style guidelines

From SIPfoundry sipx, The Open Source SIP PBX for Linux - Calivia

Jump to: navigation, search
Important note: This page is DRAFT only. Information here is mostly correct, but may be not formated.


Contents

[edit] Formating

[edit] Spacing Around Operators

Spacing around operators and delimiters should be consistent. In general, insert one space before or after each operator to improve readability. Concrete rules:

  • Do not use spaces inside of the parentheses around the argument list.
  void doIt(int v);               // correct
  void doIt( int v );             // not recommended
  • Do not use a space within empty argument lists () or non-dimensioned arrays [].
  void doIt();                    // correct
  void doIt( );                   // wrong
  • Do not use spaces around the member access operators . and ->.
  value = object->GetValue();     // correct
  value=object -> GetValue();     // wrong
  • Do not use spaces around the scope operator ::.
  ParentClass::doIt();            // correct
  ParentClass :: doIt();          // wrong
  • Place spaces after 'if', 'for', 'while', etc.
  if (value == 0)                 // correct
  if ( value == 0 )               // wrong
  if(value==0)                    // wrong

[edit] Misc

  • Inline definitions should visually distinguish from definitions, so place its body on new line. This also prevents 80 column overrun in many cases.
  SomeClass
  {
     LongReturnType longMemberFunctionName(VeryLongParameterType paramLongToo)            // correct
     { ... };
     LongReturnType longMemberFunctionName(VeryLongParameterType paramLongToo) { ... };   // not recommended
  }


[edit] Recomendations

[edit] Writing constructors

  • Member variables should be initialized in initialization section, not in constructor body.
  SomeClass::SomeClass()
  : mFirstInt(0)                  // correct
  , mSecondInt(0)                 // correct
  , mAndSoOn(TRUE)                // correct
  {
     ...
     mAndSoOn = TRUE;             // not recommended
     mFirstInt = 0;               // not recommended
     mSecondInt = 0;              // not recommended
  }
  • If constructor parameter is stored in member variable, then use member variable in constructor body to prevent errors such as XPL-180.
  SomeClass::SomeClass(int someData)
  : mSomeData(someData)
  {
     ...
     if (mSomeData > 0)           // correct
     ...
     if (someData > 0)            // not recommended
  }
  • Member variables should be initialized in the same order they declared.
  class FatClass
  {
     FatClass(int intParam)
     : mFirstInt(0)               // correct
     , mThirdInt(intParam)        // correct itself, but cause error in mSecondInt initialization
     , mSecondInt(mThirdInt-1)    // wrong.. according to C++ standard mSecondInt will be initialized
                                  // before mThirdInt
     {
     }
  
     int mFirstInt;
     int mSecondInt;
     int mThirdInt;
  }
Personal tools