Skip to content

Commit c495db8

Browse files
authored
Simplify coding style (InfiniTimeOrg#1280)
1 parent 093a66c commit c495db8

File tree

1 file changed

+29
-41
lines changed

1 file changed

+29
-41
lines changed

doc/coding-convention.md

+29-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
# Coding convention
2-
3-
## Language
4-
5-
The language of this project is **C++**, and all new code must be written in C++. (Modern) C++ provides a lot of useful tools and functionalities that are beneficial for embedded software development like `constexpr`, `template` and anything that provides zero-cost abstraction.
6-
7-
C code is accepted if it comes from another library like FreeRTOS, NimBLE, LVGL or the NRF-SDK.
8-
9-
## Coding style
10-
11-
The most important rule to follow is to try to keep the code as easy to read and maintain as possible.
12-
13-
Using an autoformatter is highly recommended, but make sure it's configured properly.
14-
15-
There are preconfigured autoformatter rules for:
16-
17-
* CLion (IntelliJ) in [.idea/codeStyles/Project.xml](/.idea/codeStyles/Project.xml)
18-
* `clang-format`
19-
20-
Also use `clang-tidy` to check the code for other issues.
21-
22-
If there are no preconfigured rules for your IDE, you can use one of the existing ones to configure your IDE.
23-
24-
- **Indentation** : 2 spaces, no tabulation
25-
- **Opening brace** at the end of the line
26-
- **Naming** : Choose self-describing variable name
27-
- **class** : PascalCase
28-
- **namespace** : PascalCase
29-
- **variable** : camelCase, **no** prefix/suffix ('_', 'm_',...) for class members
30-
- **Include guard** : `#pragma once` (no `#ifdef __MODULE__ / #define __MODULE__ / #endif`)
31-
- **Includes** :
32-
- files from the project : `#include "relative/path/to/the/file.h"`
33-
- external files and std : `#include <file.h>`
34-
- use includes relative to included directories like `src`, not relative to the current file. Don't do: `#include "../file.h"`
35-
- Only use [primary spellings for operators and tokens](https://en.cppreference.com/w/cpp/language/operator_alternative)
36-
- Use auto sparingly. Don't use auto for [fundamental/built-in types](https://en.cppreference.com/w/cpp/language/types) and [fixed width integer types](https://en.cppreference.com/w/cpp/types/integer), except when initializing with a cast to avoid duplicating the type name.
37-
- Examples:
38-
- `auto* app = static_cast<DisplayApp*>(instance);`
39-
- `auto number = static_cast<uint8_t>(variable);`
40-
- `uint8_t returnValue = MyFunction();`
41-
- Use nullptr instead of NULL
1+
# Coding style
2+
3+
## Use these tools to find and fix issues.
4+
5+
- Use `clang-format` to format the code.
6+
- Use `clang-tidy` to check the code for other potential issues.
7+
8+
## Follow these guidelines while writing code.
9+
10+
- **Indentation** : 2 spaces, no tabulation
11+
- **Opening brace** at the end of the line
12+
- **Naming** : Choose self-describing variable name
13+
- **class** : PascalCase
14+
- **namespace** : PascalCase
15+
- **variable** : camelCase, **no** prefix/suffix (`_`, `m_`,...) for class members
16+
- **Include guard** : `#pragma once` (no `#ifdef __MODULE__ / #define __MODULE__ / #endif`)
17+
- **Includes** :
18+
- files from the project : `#include "relative/path/to/the/file.h"`
19+
- external files and std : `#include <file.h>`
20+
- use includes relative to included directories like `src`, not relative to the current file. Don't do: `#include "../file.h"`
21+
- Only use [primary spellings for operators and tokens](https://en.cppreference.com/w/cpp/language/operator_alternative)
22+
- Use `auto` sparingly. Don't use `auto` for [fundamental/built-in types](https://en.cppreference.com/w/cpp/language/types) and [fixed width integer types](https://en.cppreference.com/w/cpp/types/integer), except when initializing with a cast to avoid duplicating the type name.
23+
```c++
24+
// Examples:
25+
auto* app = static_cast<DisplayApp*>(instance);
26+
auto number = static_cast<uint8_t>(variable);
27+
uint8_t returnValue = MyFunction();
28+
```
29+
- Use `nullptr` instead of `NULL`

0 commit comments

Comments
 (0)