For easier coding, here are few conventions similar to the one for ILCSoft.


These conventions are made in order to

  • Enhance the readability of the code
  • Increase the understanding of the code
  • Improve maintainability and quality of the code
These guidelines are here to help you!


Compilation

Your code should not introduce any new warnings, and fix as many existing warnings as possible. Correct the warnings until none are left!


Variable and type names

  • Variable names start with lower case and every following word with upper case: int someVariable ;
  • The larger the scope, the more explicit the variable name: float largestCellEnergy ;
  • Loop variables typically are I,j,k,l,m,n...
  • Type names start with a upper case and every following word with a upper case: class Ahc2CalibrateProcessor ;

Methods and Functions

  • Start with a lower case and followed by upper case: Ahc2CalibrateProcessor::getCalibrations() ;
  • Methods get/set are used to read/modify simple attributes: float getEnergy() / void setEnergy(float energy) 
  • Booleans start with 'is' or 'has': isMuon(), hasTrack() ...

Constants

  • All upper case: M_PI, NLAYERS ...
  • Prefer use of static class members than #defines
  • public class member should always be constant (use protected/private otherwise)



Members

  • Member variables should be prefixed with '_' to distinguish them from local variables
class Tile{
//...
protected:
	double _width ;
	double _thickness ;
	double _position[3] ;
};

Casts


Style

  • Use indentations (tab or 2,3,4 characters)
  • Avoid squeezing the code to improve readability

Documentation

Please document your code. This is important!

/** Describe what the class does 
* Describe the use case
*
* @author 
* @version $Id: $
*/

class SomeNewClass { ... 
};
  • Document at least the classes and members/functions
  • Use C++ comments in the code "//"

Coding

  • Prefer the use of STL containers and algorithms than self-written code: 
    • vectors, maps, pair, iterators...
    • copy, sort, find ...
  • Keep it simple!
  • No labels