Skip to content

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.

General

  • NEVER use using namespace my_namespace; in headers! Prefer using 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, prefer static_cast, dynamic_cast (or if it's absolutely unavoidable reinterpret_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.

FairRoot/FairShip specific

  • PREFER LOG(SEVERITY) macros to std::cout or the older FairLogger->Severity(...) methods.
  • ALWAYS use TFile::Open instead of using the TFile constructor directly
  • PREFER STL vectors or RVecs over TVectorT
  • PREFER STL containers or RTensor over TMatrix
Clone this wiki locally