Coding Standards¶
Code style and conventions for Radix Relay.
General Principles¶
- Readability First - Prefer clarity over cleverness
- Maintainability - Code should be easy to modify
- Testability - Design for testing
- Simplicity - Keep it simple
C++ Standards¶
Style Guide¶
Follow C++ Core Guidelines
Modern C++¶
- Use C++20 features
- Prefer standard library over custom code
- Use trailing return types
- Use
autowhere type is obvious
Memory Management¶
- Prefer references over pointers
- Use smart pointers when ownership is needed
- Avoid raw
new/delete
Naming Conventions¶
All identifiers use snake_case (enforced by clang-tidy):
// Classes and structs: lower_case
class signal_bridge { };
struct message_handler { };
// Functions and methods: lower_case
auto process_message() -> void;
// Variables: lower_case
int message_count = 0;
// Enums and enum constants: lower_case
enum class transport_type { nostr, ble };
// Type aliases: lower_case with _t suffix
using session_id_t = std::string;
// Namespaces: lower_case
namespace radix_relay::core { }
Formatting and Linting¶
Run code quality checks using the quality CMake target:
This runs clangd-tidy which applies clang-format and clang-tidy checks configured in:
- .clang-format - Code formatting rules
- .clang-tidy - Static analysis configuration
Rust Standards¶
Style Guide¶
Follow Rust Style Guide
Idioms¶
- Use the type system to prevent errors
- Prefer
Resultover panics - Use
Optioninstead of null - Implement traits for common operations
Formatting¶
Uses rustfmt with project configuration:
Linting¶
Uses clippy for additional checks:
Git Practices¶
Commit Messages¶
Use gitmoji prefixes:
:sparkles: add new feature
:bug: fix issue with X
:memo: update documentation
:recycle: refactor code
:white_check_mark: add tests
Branch Names¶
Pull Requests¶
- One feature per PR
- Include tests
- Update documentation
- Pass CI checks
Documentation¶
Code Comments¶
- Explain why, not what
- Comment complex logic
- Use doc comments for public APIs
C++ Documentation¶
/// Brief description
///
/// Detailed description
/// @param name Parameter description
/// @return Return value description
auto function(int name) -> int;
Rust Documentation¶
/// Brief description
///
/// Detailed description
///
/// # Arguments
/// * `name` - Parameter description
///
/// # Returns
/// Return value description
pub fn function(name: i32) -> i32 {
}
Code Review¶
All changes require code review:
- Check for correctness
- Verify tests exist and pass
- Ensure documentation is updated
- Confirm style compliance
- Look for potential improvements