Coding style - Sheba/MAI_SCADA GitHub Wiki

A small Style Guideline.

The guide is taken from Designing Qt-Style C++ APIs, by Matthias Ettrich, published by Trolltech.

  • Class names begin with a capital letter: class Customer
  • Function names begin with a lowercase letter.
  • Although permitted by the compiler, periods, underscores, dashes, and funny characters should be avoided whenever possible (except wherenoted below).
  • Multi-word names have subsequent words capitalized: class FileTagger void getStudentInfo() for example.
  • Constants should be in CAPS.
  • Each class name should be a noun or a noun phrase: class LargeFurryMammal; for example.
  • Each function name should be a verb or a verb phrase: processBookOrder(); for example.
  • Each bool variable name should produce a reasonable approximation of a sentence when used in an if() statement: bool isQualified; for example.

For data members, we will use a common prefix.

  • Member name: m_Color, m_Width (prepend lowercase m_)
  • static data members: sm_Singleton, sm_ObjCount

For each attribute, we have naming conventions for their corresponding getters/setters.

  • Non-boolean getters getColor()
  • Boolean getters: isChecked() or isValid()
  • Setter: setColor(const Color& newColor);

For brackets:

int foo()  // good
{           
//…
}
int foo()  { // bad
//…
}

We will use 2 space indent.

int foo()  
{//…
  int val;
  for(int i=0;i<100;i++)
  {
     val=val+5;  
  }
}

Try to be consistent in your code. A consistent naming convention greatly improves the readability and maintainability of a program.