Fork us on GitHub Follow us on Facebook Follow us on Twitter

Version 2 (modified by Jiri Svoboda, 7 years ago) (diff)

More on bracing, Yoda comparison

HelenOS Coding Style Standard

Entity Naming

  • Names' words shall be separated by underscore "_".
  • Types shall be suffixed with "_t".
  • Macros shall be upper case.

Names

  • Use sensible, descriptive names.
  • Only use English names.
  • Variables with a large scope should have long names, variables with a small scope can have short names.
  • Use name prefixes for identifiers declared in different modules.

Indentation and Spacing

  • Do not use spaces for indentation, except for long line wrapping purposes.
  • Consider breaking long lines at 80-character boundary. The wrapped line should continue indented four spaces to the right of the original indentation.
  • Each statement shall be placed on a line on its own.
  • Braces shall follow K&R Bracing Style
    • I.e. for functions the opening braces starts at a new line
  • Blocks within braces shall be indented 1 tab to the right as compared to the enclosing braces
  • Braces without any contents may be placed on the same line.
  • Blocks containing a single statement can omit braces
    • For if…else statements both or neither of the T, F blocks must be delimited by braces
  • All binary arithmetic, bitwise and assignment operators and the ternary conditional operator (?:) shall be surrounded by spaces; the comma operator shall be followed by a space but not preceded; all other operators shall not be used with spaces.

Comments

  • Comments shall be written in English.
  • Multiline comments begin with "*" on each inner line.
  • Use Doxygen style comments for documenting functions.
  • All comments shall be placed above the line the comment describes, indented identically.
  • Every function shall have a comment that describes its purpose.

Miscellaneous

  • New lines are represented by the LF ('\n') character. Do not use CR + LF or CR.
  • Do *not* use Yoda comparisons (e.g. NULL == ptr)