This repository has been archived on 2023-09-28. You can view files and clone it, but cannot push or open issues or pull requests.
homepage/content/projects/noxos/docs/codestyle.md

1.9 KiB

title summary
Code Style Read this, before contributing!

The following code style should be applied to the whole noxos codebase. Pull Requests that don't follow this code style will be rejected.

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. meaningfully names. The times of 80-char 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 (definitely written 100% sober):

bool likes_pigs (void* a) {
    if (a != NULL) {
        if (a == 0xACAB) {
            return false;
        }
    }
    return true;
}

->

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:

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