Always use struct

This commit is contained in:
2025-08-23 06:10:55 -04:00
parent b86cf3680e
commit 4af5e0423e
14 changed files with 56 additions and 41 deletions

View File

@@ -72,13 +72,22 @@ void add_block(size_t size);
uint32_t initial_block_size_;
```
### Classes and Structs
- **PascalCase** for class and struct names
- **Prefer struct over class** - public members at the top, avoid `class { public:` pattern
### Structs
- **PascalCase** for struct names
- **Always use struct** - eliminates debates about complexity and maintains consistency
- **Public members first, private after** - leverages struct's default public access
- Use `private:` sections when encapsulation is needed
```cpp
struct ArenaAllocator {};
struct CommitRequest {};
struct JsonCommitRequestParser {};
struct ArenaAllocator {
// Public interface first
explicit ArenaAllocator(size_t initial_size = 1024);
void* allocate_raw(size_t size);
private:
// Private members after
uint32_t initial_block_size_;
Block* current_block_;
};
```
### Enums
@@ -173,8 +182,8 @@ std::unique_ptr<Parser> parser;
## Code Structure
### Class Design
- **Move-only semantics** for resource-owning classes
### Struct Design
- **Move-only semantics** for resource-owning structs
- **Explicit constructors** to prevent implicit conversions
- **Delete copy operations** when inappropriate
```cpp
@@ -308,7 +317,7 @@ static_assert(std::is_trivially_destructible_v<T>, "Arena requires trivially des
## Documentation
### Doxygen Style
- **/** for class and public method documentation
- **/** for struct and public method documentation
- **@brief** for short descriptions
- **@param** and **@return** for function parameters
- **@note** for important implementation notes