From 097ea74a2449166e32b2c2136ade35f00651ebe5 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Fri, 21 Feb 2025 15:52:32 -0800 Subject: [PATCH 1/4] Update SUMMARY.md with coding-rules.md --- src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 07e89227..c69c5d2b 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -39,6 +39,7 @@ - [Container-Software Compatibility](developing/compatibility.md) - [Contributing](developing/Contributing-to-ldmx-sw.md) - [PRs in ldmx-sw](developing/prs.md) + - [Coding rules](developing/coding-rules.md) - [Unit Testing](developing/Unit-Testing-in-ldmx-sw.md) - [Logging](developing/Logging.md) - [Container-less Building (not recommended)](developing/building/containerless.md) From 23bdd286c6eb08a3d68415ec8a0127d8d0949e24 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Fri, 21 Feb 2025 16:14:44 -0800 Subject: [PATCH 2/4] Add coding-rules.md --- src/developing/coding-rules.md | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/developing/coding-rules.md diff --git a/src/developing/coding-rules.md b/src/developing/coding-rules.md new file mode 100644 index 00000000..165d52a6 --- /dev/null +++ b/src/developing/coding-rules.md @@ -0,0 +1,35 @@ +# 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 +1. Avoid one letter variables, `x` +2. Use `snake_case` for local variables +3. Use `snake_case_` for global variables +4. Use `UpperCase()` for classes +5. Use `camalCase()` for functions +6. Run `just format-cpp` so the automated formatting is applied +7. For setters, include the word `set` in the beginning of the function, e.g. `setHitValsX()` +8. Do not use `__` in any c++ variable name + +## II. Packaging Rules +1. Put the header files with the extension of `.h` into `Package/include/Package/MyFile.h` +2. Put the c++ file with the extension of `.cxx` into `Package/src/Package/MyFile.cxx` +3. The `test` directory is for unit tests +4. Example configs should be put under `exampleConfigs` + + +## III. Code quality +1. Run UBSAN / ASAN to make sure you don’t introduce memory leaks, or undefined behavior: `just configure-asan-ubsan`, then `just build` +2. Run the LTO build: `just configure-clang-lto`, then `just build` +3. Use the default constructor if possible, i.e. `~MyClass();` should become `virtual ~MyClass() = default;` +4. If you inherit from a class and you overwrite its function, don't forget `override`, e.g. `void configure(framework::config::Parameters&) override;` +5. Do not inline virtual functions +6. Do not let const member functions change the state of the object +7. Keep the ordering of methods in the header file and in the source file identical. +8. Move `cout`-s to the ldmx logging system, see (developing/Logging.md) +9. Delete commented out code, or move them to `ldmx_log(trace)` if you think it's helpful for a future developer +10. When updating code, be sure to update and revise comments too +11. Set all parameters to be `const` that do not need to be non-const. +12. Use `constexpr` for all constant values that can be evaluated at compile time +13. Do not use magic numbers From e227307175d488a04721789e963cdeb8ae00ba55 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Fri, 21 Feb 2025 16:16:37 -0800 Subject: [PATCH 3/4] Update coding-rules.md --- src/developing/coding-rules.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/developing/coding-rules.md b/src/developing/coding-rules.md index 165d52a6..845b18a1 100644 --- a/src/developing/coding-rules.md +++ b/src/developing/coding-rules.md @@ -17,6 +17,7 @@ When developing code in ldmx-sw please follow the following best practises and s 2. Put the c++ file with the extension of `.cxx` into `Package/src/Package/MyFile.cxx` 3. The `test` directory is for unit tests 4. Example configs should be put under `exampleConfigs` +5. All producers should have a configurable pass names, input collection names, and output collection names ## III. Code quality From d224c8445ab880df9877ba41cfc7cddb3b6811ad Mon Sep 17 00:00:00 2001 From: Tom Eichlersmith <31970302+tomeichlersmith@users.noreply.github.com> Date: Mon, 24 Feb 2025 08:35:48 -0600 Subject: [PATCH 4/4] small edits from read through --- src/developing/coding-rules.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/developing/coding-rules.md b/src/developing/coding-rules.md index 845b18a1..e5e3f2f2 100644 --- a/src/developing/coding-rules.md +++ b/src/developing/coding-rules.md @@ -5,7 +5,7 @@ When developing code in ldmx-sw please follow the following best practises and s ## I. Naming conventions 1. Avoid one letter variables, `x` 2. Use `snake_case` for local variables -3. Use `snake_case_` for global variables +3. Use `snake_case_` for class member variables 4. Use `UpperCase()` for classes 5. Use `camalCase()` for functions 6. Run `just format-cpp` so the automated formatting is applied @@ -28,7 +28,7 @@ When developing code in ldmx-sw please follow the following best practises and s 5. Do not inline virtual functions 6. Do not let const member functions change the state of the object 7. Keep the ordering of methods in the header file and in the source file identical. -8. Move `cout`-s to the ldmx logging system, see (developing/Logging.md) +8. Move `cout`-s to the ldmx logging system, see [Logging](developing/Logging.md) 9. Delete commented out code, or move them to `ldmx_log(trace)` if you think it's helpful for a future developer 10. When updating code, be sure to update and revise comments too 11. Set all parameters to be `const` that do not need to be non-const.