Coding rules for development in ldmx-sw
When developing code in ldmx-sw please follow the following best practises and style rules
I. Naming conventions
- Avoid one letter variables,
x - Use
snake_casefor local variables - Use
snake_case_for class member variables - Use
UpperCase()for classes - Use
camalCase()for functions - Use
lowercasefor namespaces - Run
just format-cppso the automated formatting is applied - For setters, include the word
setin the beginning of the function, e.g.setHitValsX() - Set the value of the setter in the header, i.e. make the relevant quanities class members
- Do not use
__in any c++ variable name
II. Packaging Rules
- Put the header files with the extension of
.hintoPackage/include/Package/MyFile.h - Put the c++ file with the extension of
.cxxintoPackage/src/Package/MyFile.cxx - The
testdirectory is for unit tests - Example configs should be put under
exampleConfigs - All producers should have a configurable pass names, input collection names, and output collection names
- Put the
#includelines into the.hheader file, instead of the.cxxfiles
III. Code quality
- Run UBSAN / ASAN to make sure you don’t introduce memory leaks, or undefined behavior:
just configure-asan-ubsan, thenjust build - Run the LTO build:
just configure-clang-lto, thenjust build - Use the default constructor if possible, i.e.
~MyClass();should becomevirtual ~MyClass() = default; - If you inherit from a class and you overwrite its function, don't forget
override, e.g.void configure(framework::config::Parameters&) override; - Do not inline virtual functions
- Do not let const member functions change the state of the object
- Keep the ordering of methods in the header file and in the source file identical.
- Move
cout-s to the ldmx logging system, see Logging - Delete commented out code, or move them to
ldmx_log(trace)if you think it's helpful for a future developer - When updating code, be sure to update and revise comments too
- Set all parameters to be
constthat do not need to be non-const. - Use
constexprfor all constant values that can be evaluated at compile time - Do not use magic numbers