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_case
for local variables - Use
snake_case_
for class member variables - Use
UpperCase()
for classes - Use
camalCase()
for functions - Use
lowercase
for namespaces - Run
just format-cpp
so the automated formatting is applied - For setters, include the word
set
in 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
.h
intoPackage/include/Package/MyFile.h
- Put the c++ file with the extension of
.cxx
intoPackage/src/Package/MyFile.cxx
- The
test
directory 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
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
const
that do not need to be non-const. - Use
constexpr
for all constant values that can be evaluated at compile time - Do not use magic numbers