|
1 | | -# Coding Guideline |
| 1 | +# Coding Guideline <!-- omit in toc --> |
2 | 2 |
|
3 | 3 | Derived from existing source code in this repository. |
4 | 4 |
|
5 | | ---- |
| 5 | +## Table of Contents <!-- omit in toc --> |
| 6 | + |
| 7 | +- [File Structure](#file-structure) |
| 8 | +- [Naming](#naming) |
| 9 | +- [Headers](#headers) |
| 10 | +- [Doxygen](#doxygen) |
| 11 | +- [Class Layout](#class-layout) |
| 12 | +- [Patterns](#patterns) |
| 13 | + - [Singleton](#singleton) |
| 14 | + - [State Machine](#state-machine) |
| 15 | +- [Formatting](#formatting) |
| 16 | +- [Conditionals](#conditionals) |
| 17 | + - [Switch](#switch) |
| 18 | +- [Parameters](#parameters) |
| 19 | +- [Logging](#logging) |
| 20 | +- [Tests](#tests) |
6 | 21 |
|
7 | 22 | ## File Structure |
8 | 23 |
|
@@ -48,25 +63,23 @@ Each section uses a 80-character comment banner: |
48 | 63 | Close every header file with: |
49 | 64 |
|
50 | 65 | ```cpp |
51 | | -#endif /* FILENAME_H */ |
52 | | - |
53 | 66 | /** @} */ |
54 | 67 | ``` |
55 | 68 |
|
56 | 69 | --- |
57 | 70 |
|
58 | 71 | ## Naming |
59 | 72 |
|
60 | | -| Element | Convention | Example | |
61 | | -|---|---|---| |
62 | | -| Class | PascalCase | `StateMachine`, `StartupState` | |
63 | | -| Interface / abstract base | Prefix `I` | `IState`, `IBoard` | |
64 | | -| Method | camelCase | `setup()`, `getInstance()` | |
65 | | -| Private member variable | `m_` prefix + camelCase | `m_isActive`, `m_duration` | |
66 | | -| Constant / `static const` member | `UPPER_SNAKE_CASE` | `MIN_BATTERY_LEVEL`, `SEND_WAYPOINT_TIMER_INTERVAL` | |
67 | | -| File-scope static variable | `g` prefix + camelCase | `gLogSinkSerial` | |
68 | | -| Macro parameter | double-underscore prefix | `SIMPLE_TIMER_SECONDS(__timeInS)` | |
69 | | -| Enum value | `UPPER_SNAKE_CASE` | `CMD_GET_MAX_SPEED`, `CMD_NONE` | |
| 73 | +| Element | Convention | Example | |
| 74 | +| -------------------------------- | ------------------------ | --------------------------------------------------- | |
| 75 | +| Class | PascalCase | `StateMachine`, `StartupState` | |
| 76 | +| Interface / abstract base | Prefix `I` | `IState`, `IBoard` | |
| 77 | +| Method | camelCase | `setup()`, `getInstance()` | |
| 78 | +| Private member variable | `m_` prefix + camelCase | `m_isActive`, `m_duration` | |
| 79 | +| Constant / `static const` member | `UPPER_SNAKE_CASE` | `MIN_BATTERY_LEVEL`, `SEND_WAYPOINT_TIMER_INTERVAL` | |
| 80 | +| File-scope static variable | `g` prefix + camelCase | `gLogSinkSerial` | |
| 81 | +| Macro parameter | double-underscore prefix | `SIMPLE_TIMER_SECONDS(__timeInS)` | |
| 82 | +| Enum value | `UPPER_SNAKE_CASE` | `CMD_GET_MAX_SPEED`, `CMD_NONE` | |
70 | 83 |
|
71 | 84 | Use `uint8_t`, `uint16_t`, `uint32_t` etc. for sized integer types. Append `U` to unsigned integer literals (`50U`, `1000U`). |
72 | 85 |
|
|
0 commit comments