Fork us on GitHub Follow us on Google+ Follow us on Facebook Follow us on Twitter

Coding Tips

Mandatory coding practices

These are absolutely required for any contribution.

  • Adhere to the coding style standard
  • Document your code
    • Doxygen and regular comments
  • Adhere to RCS rules from the very beginnning
    • Use Git for revision control
    • Separate into reasonably-sized changesets
    • Make sure that each commit is accompanied by a commit message that follows the example below. The first line should be a short description of WHAT the commit does written in imperative mood. It should not exceed 50 columns of text width and the trailing period should be omitted. The next line should be empty. Optionally, you may provide additional paragraphs that explain WHY the change was made. The text should not exceed 72 columns of width. Note that some editors will help you follow these rules by text highlighting. The entire commit message must be written in English.
      Make INTERFACE_LOC_SUPPLIER parallel
          
      Location service sometimes needs to be able to process requests in
      parallel in order to avoid deadlock.
      

Recommended coding practices

Good coding practices that are highly recommended (but cannot be mandatory, since they're not necessarily measurable).

  • Principle of least surprise
    • Comments are good, but code should be self-explanatory
    • Optimize code for understandability
  • Separation of concerns, divide et impera
    • Separate code into small modules, functions with well-defined interfaces (1)
  • Unit testing
    • Design for testability (2)
    • Every non-trivial module should have carefully written unit tests (PCUT)

Resources on Good Coding Practices

Preprocessor defines, macros, inline functions

  • Prefer using enum instead of preprocessor defines for constants
    • Preprocessor defines are only necessary when you are using the constant both in C and assembly sources
  • Prefer using static inline functions instead of preprocessor macros
    • Preprocessor macros are only needed (a) for type polymorphism, (b) if the result needs to be an l-value (R/W accessor)
  • Prefer using regular functions to static inline functions
    • Practically never needed, it is just premature optimization
Last modified 8 months ago Last modified on 2018-02-24T20:07:10Z