Coding style policies

Remi Lefebvre, remi@dhis.net

Benoit Joly, bj@hermes.usherb.ca

This document describes the coding policies for the project used in the project. People who want to submit patches must follow these.


Table of Contents
1. Coding style for the project
1.1. Classes and methods
1.2. Indentation
1.3. Comments
1.4. Declarations
1.5. Naming conventions
1.5.1. file
1.5.2. class
1.5.3. method or function
1.5.4. variables
1.5.5. constants or #define

Chapter 1. Coding style for the project

These are the guidelines that will be followed for coding in the project. Anyone who wants to submit patches must follow these guidelines or they would be rejected.


1.1. Classes and methods

  • declare methods and variable scope in this order: public, protected, private

  • for a given scope, always declare variable first, then methods.

  • Only inline methods or methods for a template class can be implemented in the header file

  • as much as you can, dont use public member, but function that set/get these member (especialy for pointers)


1.2. Indentation

  • indent unit is 4 space

  • dont use tabs cause it 'sux' in vi (there is an emacs setting to convert tabs in spaces)

  • if we can, restrict to 80 characters per line (because of console limitation)


1.3. Comments

  • english language (except for cool quotes in the code ;) )

  • function header comments are starting with /**, each line has a leading * and the last line is */

	  /**
	  * this function is doing nothing :)
	  */
	  void dummyFunction()
	  {
	  }
	

  • Comments in the code should be done with the // operator.


1.4. Declarations

  • one variable declaration per line:

	  int l_test;
	  int l_hello;
	  /* but not: */
	  int l_test, l_hello;
	

  • define vars at the beginning of methods

  • {} blocks are like this:

	  if (test == 0)
	  {
	  exit(1);
	  }
	


1.5. Naming conventions

1.5.1. file

  • extensions permited are .h and .cc

  • no underscore

  • space replaced with capital letter

  • should match to class name if there is a class in it.

    ex: MyClass.h and MyClass.cc


1.5.2. class

  • same rules as file

    ex: public class MyClass


1.5.3. method or function

  • no underscore

  • space replaced by capital

  • start with a small letter

    ex: void myFunction()

  • a function that returns boolean start with the word is.

  • a function that returns a value but dont change anything start with get.

  • a function that set a value start with set.

    ex:

	    boolean isOk();
	    int getValue();
	    void setValue (int i_value);
	  


1.5.4. variables

  • starts with a lower case

  • do not use lower case variable names

  • it should be easy for everyone to figure out what a variable is only with its name.

  • boolean variables all starts with 'is'

  • l prefix is used for local variables

  • i prefix is used for input parameters

  • o prefix is used for output parameters

  • io prefix is used for input/output parameters

  • member variables doesn't have any prefix

    ex:

	    member variable: myVar
	    local variable: l_myVar
	    input parameter: i_myVar
	    output parameter: o_myVar
	    input/output parameter: io_myVar
	  


1.5.5. constants or #define

  • upper case

  • spaces are replaced by underscores

    ex:

	    int MAX_SIZE = 3;
	    #define MAX_SIZE 3