... | ... | @@ -617,21 +617,16 @@ Better alternatives to `#defines` are discussed below |
|
|
## Functions
|
|
|
|
|
|
* **Write Testable Code**
|
|
|
|
|
|
Write code with the test code alongside. This is hard to capture in a guideline like this coding standards' document, but design code that is modular, and testable. Refer to the [C Unit Test Tutorial](https://gitlab.com/sibros_public/public/wikis/c/unit_tests) for more details.
|
|
|
* Write code with the test code alongside. This is hard to capture in a guideline like this coding standards' document, but design code that is modular, and testable. Refer to the [C Unit Test Tutorial](https://gitlab.com/sibros_public/public/wikis/c/unit_tests) for more details.
|
|
|
|
|
|
* **Keep the functions small**
|
|
|
|
|
|
Do not write functions that are **larger than 10 lines of meaningful code**. The benefits are:
|
|
|
|
|
|
* Do not write functions that are **larger than 10 lines of meaningful code**. The benefits are:
|
|
|
- Creates smaller units of code that are easier to test
|
|
|
- Increases code clarity
|
|
|
|
|
|
* **Do not use more than 5 brace levels in your code**
|
|
|
|
|
|
- Refactor code into smaller functions
|
|
|
- Re-structure the branch statements to reduce the curly brace nesting
|
|
|
|
|
|
* Refactor code into smaller functions
|
|
|
* Re-structure the branch statements to reduce the curly brace nesting
|
|
|
|
|
|
* **No recursive functions**
|
|
|
- In Embedded Systems, the stack memory is precious, as there is usually not very much.
|
... | ... | |