-
Notifications
You must be signed in to change notification settings - Fork 117
CPP guidelines
Oliver Lantwin edited this page Dec 10, 2024
·
4 revisions
General guidelines to improve the quality and readability of our C++ code. For python, see the python guidelines.
- NEVER use
using namespace my_namespace;
in headers! Preferusing my_namespace::my_symbol;
or prepending the namespace at the location the symbol is used. - NEVER use C-style casts (e.g.
(TTree *)file->Get("some_tree")
;). INSTEAD, preferstatic_cast
,dynamic_cast
(or if it's absolutely unavoidablereinterpret_cast
), in that order. - PREFER range-based for loops over containers
- CONSIDER whether
auto
can reduce verbosity by avoiding repeating types - AVOID raw pointers in favour of smart-pointers (
unique_ptr
,shared_ptr
,weak_ptr
) - PREFER STL containers over ROOT containers or C-style arrays.
- PREFER
LOG(SEVERITY)
macros tostd::cout
or the olderFairLogger->Severity(...)
methods. - ALWAYS use
TFile::Open
instead of using theTFile
constructor directly - PREFER STL vectors or RVecs over TVectorT
- PREFER STL containers or RTensor over TMatrix