2022-01-05 16:10:18 +00:00
|
|
|
# Intro
|
|
|
|
|
|
|
|
Nice to see you reading this document, we really appreciate it.
|
|
|
|
|
|
|
|
As all documents of this kind it's unable to cover everything.
|
2022-12-28 14:30:20 +00:00
|
|
|
But it will cover general rules that we are enforcing on PR review.
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2022-12-28 14:30:20 +00:00
|
|
|
Also, we already have automatic rules checking and formatting,
|
|
|
|
but it got its limitations and this guide is still mandatory.
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2022-12-28 14:30:20 +00:00
|
|
|
Some part of this project do have its own naming and coding guides.
|
2022-01-05 16:10:18 +00:00
|
|
|
For example: assets. Take a look into `ReadMe.md` in assets folder for more details.
|
|
|
|
|
2022-12-28 14:30:20 +00:00
|
|
|
Also, 3rd party libraries are none of our concern.
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
And yes, this set is not final and we are open to discussion.
|
|
|
|
If you want to add/remove/change something here please feel free to open new ticket.
|
|
|
|
|
|
|
|
# Inspiration
|
|
|
|
|
|
|
|
Our guide is inspired by, but not claiming to be compatible with:
|
|
|
|
|
|
|
|
- https://www.kernel.org/doc/html/v4.10/process/coding-style.html
|
|
|
|
- https://docs.unrealengine.com/en-US/Programming/Development/CodingStandard
|
|
|
|
- https://webkit.org/code-style-guidelines/
|
|
|
|
|
|
|
|
# General rules
|
|
|
|
|
|
|
|
## Readability and Simplicity first
|
|
|
|
|
|
|
|
Code we write is intended to be public.
|
|
|
|
Avoid one-liners from hell and keep code complexity under control.
|
2022-12-28 14:30:20 +00:00
|
|
|
Try to make code self-explanatory and add comments if needed.
|
2022-01-05 16:10:18 +00:00
|
|
|
Leave references to standards that you are implementing.
|
|
|
|
Use project wiki to document new/reverse engineered standards.
|
|
|
|
|
|
|
|
## Variable and function names must clearly define what it's doing
|
|
|
|
|
|
|
|
It's ok if it will be long, but it should clearly state what it's doing, without need to dive into code.
|
|
|
|
This also applies to function/method's code.
|
|
|
|
Try to avoid one letter variables.
|
|
|
|
|
|
|
|
## Encapsulation
|
|
|
|
|
|
|
|
Don't expose raw data, provide methods to work with it.
|
|
|
|
Almost everything in flipper firmware is built around this concept.
|
|
|
|
|
|
|
|
# C coding style
|
|
|
|
|
|
|
|
- Tab is 4 spaces
|
2022-06-26 12:00:03 +00:00
|
|
|
- Use `fbt format` to reformat source code and check style guide before commit
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
## Naming
|
|
|
|
|
|
|
|
### Type names are CamelCase
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
FuriHalUsb
|
|
|
|
Gui
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzKeystore
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
### Functions are snake_case
|
|
|
|
|
|
|
|
furi_hal_usb_init
|
|
|
|
gui_add_view_port
|
|
|
|
subghz_keystore_read
|
|
|
|
|
|
|
|
### File and Package name is a prefix for it's content
|
|
|
|
|
|
|
|
This rule makes easier to locate types, functions and sources.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
We have abstraction that we call `SubGhz Keystore`, so there will be:
|
|
|
|
file `subghz_keystore.h` we have type `SubGhzKeystore` and function `subghz_keystore_read`.
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
### File names
|
|
|
|
|
|
|
|
- Directories: `^[0-9A-Za-z_]+$`
|
|
|
|
- File names: `^[0-9A-Za-z_]+\.[a-z]+$`
|
|
|
|
- File extensions: `[ ".h", ".c", ".cpp", ".cxx", ".hpp" ]`
|
|
|
|
|
|
|
|
Enforced by linter.
|
|
|
|
|
|
|
|
### Standard function/method names
|
|
|
|
|
|
|
|
Suffixes:
|
|
|
|
|
|
|
|
- `alloc` - allocate and init instance. C style constructor. Returns pointer to instance.
|
2022-12-28 14:30:20 +00:00
|
|
|
- `free` - de-init and release instance. C style destructor. Takes pointer to instance.
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
# C++ coding style
|
|
|
|
|
|
|
|
Work In Progress. Use C style guide as a base.
|
|
|
|
|
|
|
|
# Python coding style
|
|
|
|
|
|
|
|
- Tab is 4 spaces
|
|
|
|
- Use [black](https://pypi.org/project/black/) to reformat source code before commit
|