Here is a set of rules I try to follow which help me to edit my code more
effectively. Nothing very deep but consistency in the picture of software
helps read, debug and modify it easier.
Find your own rules and try to stick to them. It will make your code apear
and be more organized. Writing up your rules helps you of making sure you
know what they really are.
0. Always make the code fit in 80 columns, no trailing empty lines in any file
no unneccessary empty lines (two are too much!), no trailing blanks
at the end of a non-empty line
1. Variable names
a) in general variables start with small letters
a) avoid underlines to separate blocks
myVar is much better than my_var
b) class variables (data fields)
in MixFit and AC++: use "_" upfront and start small.
for example: _myClassVar
in Stntuple: use "f" upfront and continue capital
for example: fClassVar
2. Example for if statements (watch spacings between if, parentethes etc.)
a) simple (if statement on one line, executable statement on next line(s)
if (myVariable > 25 || thisVariable < 2)
return;
else
printf("ELSE\n");
b) with else if
if (myVariable > 25 || thisVariable < 2) {
printf("Blah.\n");
...
}
else if (myVariable > 25 || thisVariable > 2 ||
anotherVariable <= 20 ) {
printf("Blah Blah.\n");
...
}
else {
printf("Be happy.\n");
...
return;
}
3. Methods
void MyClass::ThisMethod(int iVar, float xVar)
{
double here = 0.0;
....
return;
}
4. Comments
....
//---------------------------------------------------------------------------
// Here I make a big comment for a bigger code unit
//---------------------------------------------------------------------------
// Here the small comment for the few following lines
if (thisComment == TString("hello world"))
cout << "Hello World\n";
else
return;
// Some more small comments
for (int i=0; i