Code and comments are written in American English.
Keep comments short and specific.
Do not leave your initials anywhere.
Do not talk to yourself (“I wonder why …”).
Do not state the obvious or repeat the code:
// Right// From testing: clients under load may take 600ms to respond.// Set timeout to 1s to avoid false positive connection issues.inttimeout=1000;// Wrong// Set timeout to 1 second.inttimeout=1000;
Be precise:
// RightvoidMyClass::foo(){// Lazy init as fallback if parent component did not initialize prior.if(obj==nullptr)obj=NEWObject;}// WrongvoidMyClass::foo(){// May sometimes not be initialized.if(obj==nullptr)obj=NEWObject;}
Do not express philosophical thoughts.
Do not use comments to compensate missing social interaction between programmers.
Do not add class method descriptions to file headers.
Do not mention ticket numbers.
Do not mention related code outside of current scope:
// Rightvoidprocess(){// Check if data is valid before processingif(!isValid(data))return;}// Wrongvoidprocess(){// See validate() in utils.cpp for related logicif(!isValid(data))return;}
Use regular C++ comments for implementation details:
// Single-line example comment.intx=0;/* Alternative single-line example comment. */intx=0;// Multi-line example comment composed// of multiple rows of text.intx=0;/* Alternative multi-line example comment composed of multiple rows of text. */intx=0;
Use Doxygen comments for interfaces:
//********************************************************// IMyInterface/** Demo interface *///********************************************************interfaceIMyInterface{/** Do some work. \param state some argument \return kResultOk for success, kResultFalse otherwise. */virtualtresultCCL_APIdoWork(boolstate)=0;};
Use Doxygen comments for class declarations:
//************************************************************************// MyClass/** Specify here what your class is doing. *///************************************************************************classMyClass:publicBaseClass{public:MyClass();/** Long comment. */voidtestMethodOne();voidtestMethodTwo();///< short comment};
Comments
General Rules
Code and comments are written in American English.
Keep comments short and specific.
Do not leave your initials anywhere.
Do not talk to yourself (“I wonder why …”).
Do not state the obvious or repeat the code:
Be precise:
Do not express philosophical thoughts.
Do not use comments to compensate missing social interaction between programmers.
Do not add class method descriptions to file headers.
Do not mention ticket numbers.
Do not mention related code outside of current scope:
Formats
Use regular C++ comments for implementation details:
Use Doxygen comments for interfaces:
Use Doxygen comments for class declarations: