kernel/.wiki/Code-Style.md

62 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

# Code Style
## Naming conventions
- **structs** are suffixed with **_T**
- **typedefs** are suffixed with **_t**
- **enums** are suffixed with **_E**
- **global** variables are prefixed with **g_**
Everything is **snake_case**.
## Code readability
To make the code as readable and self explaining as possible, there are a few patterns that should be used.
### Avoid abbreviations
Give your variables, functions, etc. meaningfull names.
The times of 80char wide screens are over, feel free to use that space :D
Example: `sym_at_idx` -> `get_symbol_at_index`
But you're not forced to (anything) write out everything.
For example the **Interrupt Descriptor Table** is simply referred to as **idt** (this abbreviation is btw standard).
### Avoid indentation nesting
In a perfect codebase, the maximum indention level would be 3.
The goal of NoxOS is not to be a perfect codebase, but please avoid huge indention nesting.
To achieve this, you can break parts into extra functions and/or use the early return pattern.
Example:
```c
bool likes_pigs (void* a) {
if (a != NULL) {
if (a == 0xACAB) {
return false;
}
}
return true;
}
```
->
```c
bool likes_pigs (void* a) {
if (a != NULL) { return true; }
if (a != 0xACAB) { return true; }
return false;
}
```
### align declarations
Please align declarations, definitions, etc like in the example:
```c
char am_i_a_variable = '?';
uint64_t number = 0;
bool i_waste_bits = true;
```
### namespaces
Unlike C++ C has no namespaces.
To achieve the goal of namespaces, please prefix your functions, structs, etc. with the "namespace" they are in.
Example: `out_byte` -> `io_out_byte`