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
- Restrict to simple control flow constructs.
- Give all loops a fixed upper-bound.
- Do not use dynamic memory allocation after initialization.
- Limit functions to no more than 60 lines of text.
- Use minimally two assertions per function on average.
- Declare data objects at the smallest possible level of scope.
- Check the return value of non-void functions, and check the validity of function parameters.
- Limit the use of the preprocessor to file inclusion and simple macros.
- Limit the use of pointers. Use no more than two levels of dereferencing per expression.
- Compile with all warnings enabled, and use one or more source code analyzers.