Skip to content

Coding Style Guidelines

Kaspar Schmid edited this page Apr 15, 2015 · 4 revisions

If you are a contributor to the SLProject please follow the following coding style:

Naming Convention

  • Everything is in English (names, comments just everything!)
  • Classes belonging to the Image Play Library have the prefix IPL (e.g.: IPLData)
  • Classes belonging to the Image Play application have the prefix IP (e.g.: IPZoomWidget)
  • UI Classes don't have a prefix (e.g.: MainWindow)
  • All class headers are within a file of the same name with the extension .h
  • All class implementations are within a file of the same name with the extension .cpp
  • All method names begin with a small letter
  • All private member variables begin with an underscore (e.g.: _image)
  • All setters have the same name as the member variable without the underscore
  • All getters have the same name as the member variable without the underscore
  • All names use camel case (e.g.: processInput(), IPLData)
  • All classes should use initialization lists for non basic types to increase efficency
  • Pointer and reference symbols are always on the left (Type* ptr, Type& ref)
  • When declaring multiple pointers or references always use a new line per variable. Don't do this: Type* ptr, *ptr2, *ptr2;
  • If a variable has a unit append it to the variable name (angleRAD, angleDEG, speedKMH)
  • Try to use short names for variable that are used very often.
  • The std name space is included.

Formatting

  • IDENTIFICATION: 4 SPACES, NO TAB SIGNS
  • BRACES: IN FRONT OF THE BLOCK
  • First line: On the same or the next line of the opening brace
  • Parameters: No space after ( and before ).
  • One space after keywords (if, for, do, while, switch, ...)
  • One space before and after all types of operators
  • Line break if line is longer than 80 characters.
  • Short code after if, for or while can be on the same line without braces:
void IPLExampleClass::exampleMethod(int index)
{	
    if (index == 1) return;

    if (index == 2)
        return;

    if (index == 3)
    {   return;
    }

    if (index == 4)
    {	
        return;
    }
}

Commenting

  • Comment as much as necessary.
  • We use the Doxygen tool for the source code documentation.
  • Comment code objects (classes, structs, members & methods) with Doxygen tags:
    • The short comment tag before a code object is //!
    • The short comment tag behind a code object is //!<
    • The long comment tag is /*< ... */
    • Comment a class with a short AND a long comment in the header file
    • Comment all member variables with a short comment behind the member in the header file
    • Comment all methods with a short and/or long comment in the implementation file
//! The IPLExampleClass is just an example for commenting.
/*! This example class serves as an example how we use the Doxygen tags
to comment the different code objects. Classes must use always have a short
and a long comment.
*/
class IPLExampleClass 
{
    public:
        void exampleMethod (int index);

    private:
        int _index;   //!< The index is an example member

}

//! The exampleMethod is just an example with a short comment
void IPLExampleClass::exampleMethod(int index)
{	
    _index = index;
}
Clone this wiki locally