Coding conventions - nscl-hira/HiRAEVT GitHub Wiki
Pull requests submitted should have the code formatted in the ROOT style. Some import parts of this style are highlighted below.
Forward declarations vs including headers
Never include a header file when a forward declaration is sufficient. Only include header files for base classes or classes that are used by value in the class definition in a class header. Instead, you should put the majority of your #include
statements in the source file with the class implementation.
Naming conventions
Each folder in the root directory names HTName
will build into a shared object with the name libHTName
as defined by a CMakelists.txt
file in each folder. Other folders, (eg macro, icon, parameters, etc.), are not built and do not contain a CMakeLists.txt folder. In order for the new library to be built, it must be added as a subdirectory to the global CMakeList.txt in the root directory. Classes should have the prefix "HT", followed by a descriptive name in camel case. Following the ROOT naming conventions, new classes should avoid back-to-back capital letter. For example the method name for getting the x-axis from a ROOT histogram is GetXaxis
, not GetXAxis
.
All data members of a class should be private or protected and begin with the letter f
, followed by a capital letter. Boolean flags should begin with the letter k
. All member functions should begin with a capital letter. Private data members should be declared first, followed by the private static members, the private methods and the private static methods. Then the protected members and methods and finally the public methods.
Avoid raw c types for anything that might be written to disk (any member variable), instead use ROOT defined types like Int_t
defined in Rtypes.h
. If any changes are made to the memory layout of a class, the version number in the ROOT macro ClassDef
needs to be incremented. If the class overrides any virtual function, the macro ClassDefOverride
should be used instead.
All source files should have the extension .cxx
and all headers should have the extension .h
.
Formatting code for submissions
Before submitting a pull request, reformat the code using clang-format
. If run from within the repository it will pick up the .clang-format
file detail the style. This file is also reproduced on the page detailing ROOT the ROOT coding style. If for some reason you need a section of code to not be formatted, you can turn off formatting using comment flags. Formatting of code is turned off with the comment // clang-format off
and re-enabled with the comment // clang-format on
. This process can be simplified using the command git-clang-format
which when given no options will turn clang-format
on all lines of code that differ between the working directory and HEAD. Detailed documentation is here.