Skip to content

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 not std::numerics::UInt32 nor UInt32.

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.
use std;
use std::numerics;
use other_lib;
use other_lib::extra;
use other_lib::extra::download;
use other_lib::extra::import;
use std::numerics;
use std;
use other_lib::extra::download;
use other_lib::extra::import;
use other_lib::extra;
use other_lib;
  • Don't interrupt using sequence.
use other_lib;
use other_lib::extra::download;
use other_lib::extra::import;
use other_lib::extra;
use other_lib::modern;
use other_lib;
use other_lib::extra::download;
use other_lib::modern;
use other_lib::extra::import;
use other_lib::extra;

Place module after use statements

Highly recommended to place module declaration right after use statements with one empty line before the declaration.

use std;

module sigma_lib;

...
module sigma_lib;

use std;

...

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.

Comments