Coding style¶
Consistent code style is good practice to keep code more readable across whole project, that makes it more readable and makes it easier to collaborate within a development team or contributors.
Language guidelines¶
- Prefer modern features and constructions than older ones.
- Use latest language version (whenever it possible).
- Use language keywords for data types instead of them full name:
u32
but notstd::numerics::UInt32
norUInt32
.
Prefer fast boolean operators¶
- Use fast
&&
and||
boolean operators instead of&
and|
operators.
Style prefer¶
- Use K&R style for braces.
- Prefer tabulation than spaces.
- If spaces is used: use 4 spaces for indentation.
- Store prefered indentation style to
.editorconfig
file of your project. (see example)
- Do not make too long lines.
Use directive order¶
- Sort
use
statements from less nested to most.
- Don't interrupt using sequence.
Place module after use statements¶
Highly recommended to place module declaration right after use statements with one empty line before the declaration.
Comments style¶
- Use single-line comments (
//
) for brief explanations. - Place comments before the explanation part, not at the end of the line.
- Begin comment with uppercase letter.
- Insert one space between
//
and the comment text.