According Jet Propulsion Laboratory(JPL) lead scientist Gerard J. Holzmann, a huge amount of arbitrary rules and inconsistent guidelines causes code quality of even the most critical applications to suffer. “The Power of Ten: Rules for Developing Safety Critical Code” is a paper published which was an outcome of a research that was carried out at the Jet Propulsion Laboratory(JPL), California Institute of Technology, under a contract with the National Aeronautics and Space Administration(NASA).

Here are the ten rules. Although these rules are for C language, they can be applied equally well(almost) to other languages as well. For a more in depth explanation of these rules checkout this link. Also here is the link to the actual research paper “The Power of Ten — Rules for Developing Safety Critical Code,” IEEE Computer, June 2006 PDF

  1. Restrict to simple control flow constructs.
  2. Give all loops a fixed upper-bound.
  3. Do not use dynamic memory allocation after initialization.
  4. Limit functions to no more than 60 lines of text.
  5. Use minimally two assertions per function on average.
  6. Declare data objects at the smallest possible level of scope.
  7. Check the return value of non-void functions, and check the validity of function parameters.
  8. Limit the use of the preprocessor to file inclusion and simple macros.
  9. Limit the use of pointers. Use no more than two levels of dereferencing per expression.
  10. Compile with all warnings enabled, and use one or more source code analyzers.
“If there is one thing I want to go by rules, that would be programming.”