Business Practices

When trying to think of what would be the safest business practices one could follow, I tried to consider which companies had the highest requirements for safety as those would likely have some good imitable business practices. Suddenly, it hit me — NASA. I figure if you’re sending things (and people!) into outer space, you probably try to have pretty safe code.

As it turns out, one of the things NASA does is follow a set of ten rules for “safety critical code”. I won’t enumerate them in this post, but you can find a PDF with them here. Most of the rules have to do with code readability and simplicity (for example: they forbid recursion or functions which are longer than a page printed). I think codifying the need to write simple, easy to read code is an essential business practice. It can assist greatly with debugging, code reviews (by others or even yourself), and adding features in the future. If people aren’t struggling just to read your code, they’re much more likely to catch any insidious bugs you might have.

A rule worth picking out specifically is rule 7, which is essentially, “Thou shalt always check thy return values”. I have literally never had something like malloc fail in any code on any system I’ve worked on unless something else had already gone hideously (and obviously) wrong. I imagine I’m not alone in this experience. It becomes easy to not check the return values of these functions that “always work”, but if your code is really safety critical, you don’t want some horrible tragedy to occur because of some cosmic rays.

Finally, the last rule also deserves some special mention. It states that all code should be compiled with as many warnings as possible enabled, and all code must not produce any warning when compiled. It also states that all code must be checked with at least one static analysis program (which will have its own set of things to complain about), and that must also produce zero warnings. I think it’s easy to not concern yourself with the warnings (after all, your program compiled and ran, right?), but they are a good first line of defense from rare or well-hidden bugs — you’re being warned for a reason, after all.

References

Click to access P10.pdf

https://en.wikipedia.org/wiki/Soft_error#Cosmic_rays_creating_energetic_neutrons_and_protons

Leave a comment