9 Coding Conventions
Tim Svensson edited this page 2026-04-26 14:12:27 +00:00

Coding Conventions

Important Considerations

  • The intent of code should be clear
  • Keep solutions as simple as possible
  • Reuse of code is desired
  • Minimize use of External Libraries to limit dependencies

Language un-specific code conventions

  • All code, comments and documentation is to be written in English
  • We use tab to indent code, which is equal to two spaces.
  • We use spacing between comparator signs to reduce cluttering.
  • We use var instead of strongly typed datatypes.
  • A space should always be followed by a comma or semicolon.
  • A quick breakdown of what the code does is always written at the top followed by global variables.
  • Brackets are opened on the same line as the conditioner, and is ended on a separate line.
  • Variables should preferably be short and descriptive.
  • Variables should not use abbreviations unless it is already established within the codebase (example, MQTT)
  • Methods should have a purpose, or be used to avoid code duplication.
  • Comments should have a purpose. Comments should only exist if the code is hard to understand even with proper naming and formatting, or if a function is abstract enough that the name isn't a giveaway for its purpose.
  • Comments should also be used when external data is received (and what the data is).
  • Bools should use true and false, not 0, 1, null or anything else to indicate its value.
  • Checking bool values should be done with appropriate functions/comparisons.
  • Arrays are typed as follows: things = [1, 2, 3, 3] (value, comma, space)
  • Arrays are also named as plurals, as a collection of things.
  • for-loops should use index names as: i, j, k, l, etc.. If the loop ever goes beyond l, please reconsider.

Language specific code conventions