Alexander Ryzhov
Jan 22, 2025

Compiled program should never crash

If your program is compiled, it should never crash. All errors must be handled.

To achieve that, possible way is to ensure at compile-time that you have all things covered. At development-time use assertions massively for things that are logically impossible. Once you’re in production - assertions are excluded for performance, and what’s left should be considered as possible result. Possible outcomes need to be handled, all the time. Occassional panics should be unwinded and logged, and the program loop to be continued.

But this is the perfect world scenario. In a real program, even if you have NASA-level of code style, you still under a risk of program panic. In such cases you use more advanced techniques, such as several instances of a program, panic-handling, reload-on-crash, etc.

For gamedev approach of never crashing is especially valuable to preserve player’s experience. Always better to terminate the call to a system, and try later, than to crash the whole game. Sometimes a bug because of a stopped system produces unique experience. Show must go on.