-
Notifications
You must be signed in to change notification settings - Fork 135
CPP guidelines
Oliver Lantwin edited this page Jul 25, 2025
·
5 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
autocan 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::coutor the olderFairLogger->Severity(...)methods. - ALWAYS use
TFile::Openinstead of using theTFileconstructor directly - PREFER STL vectors or RVecs over TVectorT
- PREFER STL containers or RTensor over TMatrix
- PREFER using RRangeCast over manual casting when iterating over TCollections (e.g. TClonesArrays)