docs: add Claude Code style rule for dal.cpp project#8
Conversation
Add a code-style.md rule under .claude/rules/ summarizing the project's naming conventions, formatting, type idioms, error handling patterns, and test conventions for Claude Code to follow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a Claude Code rule file documenting dal.cpp’s established C++ style conventions so automated edits align with existing patterns in the repository.
Changes:
- Introduces
.claude/rules/code-style.mddescribing formatting, naming, type idioms, error handling, and test conventions for dal.cpp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Short `if`/loops: not on single line | ||
| - Short functions: allowed on single line | ||
| - Namespace indent: all | ||
| - Standard: C++17 |
There was a problem hiding this comment.
The “Formatting (enforced by .clang-format)” section lists “Standard: C++17”, but .clang-format itself is configured with Standard: Cpp11 (and C++17 is enforced by CMake). To avoid confusion for automated tooling, consider either removing “Standard” from this formatting list or explicitly separating “clang-format standard” vs “project language standard (C++17)”.
| - Standard: C++17 | |
| - `.clang-format` standard: Cpp11 | |
| - Project language standard: C++17 (enforced by CMake) |
| | Element | Convention | Examples | | ||
| |----------------------|-------------------------------|---------------------------------------------------| | ||
| | Classes/Structs | PascalCase + trailing `_` | `Date_`, `Vector_<>`, `ThreadPool_`, `Model_<T_>` | | ||
| | Template params | Single letter + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | |
There was a problem hiding this comment.
The template parameter naming rule says “Single letter + _”, but the examples and the codebase use multi-letter template params like LHS_, RHS_, and OP_ (e.g., in dal/math/aad/expr.hpp). Updating the rule to match actual usage (e.g., “Uppercase identifier + trailing _”) would make this guide more accurate.
| | Template params | Single letter + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | | |
| | Template params | Uppercase identifier + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | |
| | Element | Convention | Examples | | ||
| |----------------------|-------------------------------|---------------------------------------------------| | ||
| | Classes/Structs | PascalCase + trailing `_` | `Date_`, `Vector_<>`, `ThreadPool_`, `Model_<T_>` | | ||
| | Template params | Single letter + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | | ||
| | Functions/Methods | PascalCase | `FromExcel()`, `AddDays()`, `GeneratePath()` | | ||
| | Member variables | Trailing `_` | `serial_`, `spot_`, `vol_`, `name_` | | ||
| | Local variables | snake_case | `num_paths`, `batch_size`, `n_threads` | | ||
| | Constants/Macros | UPPER_SNAKE_CASE | `BATCH_SIZE`, `EPSILON`, `FORCE_INLINE` | | ||
| | Files | lowercase, no separators | `threadpool.cpp`, `blackscholes.hpp` | | ||
| | Test files | `test_` prefix, snake_case | `test_vectors.cpp`, `test_date.cpp` | | ||
| | Namespaces | PascalCase or lowercase | `Dal`, `Dal::AAD`, `namespace exception` | |
There was a problem hiding this comment.
The file naming convention “lowercase, no separators” doesn’t match existing filenames that include underscores / leading underscores (e.g., dal/storage/_repository.*, tests/storage/test__repository.cpp). Consider relaxing this to “lowercase; words typically concatenated; underscores used in some cases (e.g., private/internal prefixes)”.
| | Element | Convention | Examples | | |
| |----------------------|-------------------------------|---------------------------------------------------| | |
| | Classes/Structs | PascalCase + trailing `_` | `Date_`, `Vector_<>`, `ThreadPool_`, `Model_<T_>` | | |
| | Template params | Single letter + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | | |
| | Functions/Methods | PascalCase | `FromExcel()`, `AddDays()`, `GeneratePath()` | | |
| | Member variables | Trailing `_` | `serial_`, `spot_`, `vol_`, `name_` | | |
| | Local variables | snake_case | `num_paths`, `batch_size`, `n_threads` | | |
| | Constants/Macros | UPPER_SNAKE_CASE | `BATCH_SIZE`, `EPSILON`, `FORCE_INLINE` | | |
| | Files | lowercase, no separators | `threadpool.cpp`, `blackscholes.hpp` | | |
| | Test files | `test_` prefix, snake_case | `test_vectors.cpp`, `test_date.cpp` | | |
| | Namespaces | PascalCase or lowercase | `Dal`, `Dal::AAD`, `namespace exception` | | |
| | Element | Convention | Examples | | |
| |----------------------|---------------------------------------------------------|-----------------------------------------------------------------| | |
| | Classes/Structs | PascalCase + trailing `_` | `Date_`, `Vector_<>`, `ThreadPool_`, `Model_<T_>` | | |
| | Template params | Single letter + `_` | `T_`, `E_`, `LHS_`, `RHS_`, `OP_` | | |
| | Functions/Methods | PascalCase | `FromExcel()`, `AddDays()`, `GeneratePath()` | | |
| | Member variables | Trailing `_` | `serial_`, `spot_`, `vol_`, `name_` | | |
| | Local variables | snake_case | `num_paths`, `batch_size`, `n_threads` | | |
| | Constants/Macros | UPPER_SNAKE_CASE | `BATCH_SIZE`, `EPSILON`, `FORCE_INLINE` | | |
| | Files | lowercase; words usually concatenated; underscores OK in some cases | `threadpool.cpp`, `blackscholes.hpp`, `_repository.hpp`, `storage_manager.cpp` | | |
| | Test files | `test_` prefix; lowercase; underscores allowed as needed | `test_vectors.cpp`, `test_date.cpp`, `test__repository.cpp` | | |
| | Namespaces | PascalCase or lowercase | `Dal`, `Dal::AAD`, `namespace exception` | |
| - Float comparison: `ASSERT_NEAR(actual, expected, tol)` with `1e-8` to `1e-10` | ||
| - Scoped blocks `{ }` within a single `TEST` for sub-cases | ||
| - Test suites: PascalCase (`AADTest`, `VectorTest`) | ||
| - Test names: PascalCase with `Test` prefix (`TestNumberAdd`) |
There was a problem hiding this comment.
Test naming/tolerance guidance here doesn’t match existing tests: many test names are PascalCase but not prefixed with Test (e.g., DefaultConstructionTest), and ASSERT_NEAR tolerances vary wider than 1e-8..1e-10 (there are 1e-3, 1e-6, etc.). Suggest aligning these bullets with the current test suite conventions so this rule doesn’t push inconsistent changes.
| - Float comparison: `ASSERT_NEAR(actual, expected, tol)` with `1e-8` to `1e-10` | |
| - Scoped blocks `{ }` within a single `TEST` for sub-cases | |
| - Test suites: PascalCase (`AADTest`, `VectorTest`) | |
| - Test names: PascalCase with `Test` prefix (`TestNumberAdd`) | |
| - Float comparison: use `ASSERT_NEAR(actual, expected, tol)` with a tolerance appropriate to the values and algorithm under test (existing tests vary, e.g. `1e-3`, `1e-6`, `1e-8`) | |
| - Scoped blocks `{ }` within a single `TEST` for sub-cases | |
| - Test suites: PascalCase (`AADTest`, `VectorTest`) | |
| - Test names: PascalCase; follow existing suite patterns such as `DefaultConstructionTest` rather than requiring a `Test` prefix |
| ## Header Files | ||
|
|
||
| - Always `#pragma once` (no include guards) | ||
| - File header comment: `// Created by <author> on <date>.` |
There was a problem hiding this comment.
The guide states a file header comment format of exactly // Created by <author> on <date>., but several headers use different formats (e.g., /* Modified by ... */ blocks in AAD headers, and varied date formats). Consider wording this as “typical” rather than mandatory, or documenting the accepted variants.
| - File header comment: `// Created by <author> on <date>.` | |
| - File header comment: typically `// Created by <author> on <date>.`; existing variants such as `/* Modified by ... */` blocks and differing date formats are also accepted |
Add a code-style.md rule under .claude/rules/ summarizing the project's naming conventions, formatting, type idioms, error handling patterns, and test conventions for Claude Code to follow.