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
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() ...
- 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)
- Member variables should be prefixed with '_' to distinguish them from local variables
- Use explicit casts such as dynamic_cast<>, static_cast<> and reinterpret_cast<> instead of C-style casts (only for basic types)
- Use indentations (tab or 2,3,4 characters)
- Avoid squeezing the code to improve readability
Please document your code. This is important!
- Should be documented using doxygen style comments
- Document at least the classes and members/functions
- Use C++ comments in the code "//"
- Prefer the use of STL containers and algorithms than self-written code:
- vectors, maps, pair, iterators...
- copy, sort, find ...
- Keep it simple!