Writing Space-Proof Code
Meta
I learned of this from the following youtube video: How NASA Writes Space-Proof Code
Principles
- Simple Control Flow - Excluding even recursion
- Limit the maximum times a loop can run
- Don't use the heap - use only the stack and the max amt of memory the stack can use
- Limit Function Size - no more than 60 lines or what can fit on a piece of paper
- Declare variables at the lowest scope possible
- Check return values
- Limit preprocessor to file inclusions and very simple conditional macros (different platforms)
- Restrict pointer usage - one derefernce at a time and no function pointers at all
- Compile with all warnings enabled and in pedantic mode
- Use multiple static code analyzers and write unit tests
Reflections
- obviously written for C but general concepts like KISS and Testing can be applied to everywhere
- I'd love to see exceptions they made to excluding recursions if there are any and techniques one can use to avoid recursion in places you'd normally see them
- Wonder what their code does if a loop reaches its upper limit
- For other languages, I'd imagine don't use the heap can translate to prefer simple data structures and built-in operations as much as possible
- I'd like to see a better metric for limiting function size
- My translation: Atomic/Purity/Immutability + good testing and analyzing + fault-tolerant exception handling + Simple structures