by progval · 7y ago · 0 comments
* Rust has an unreachable!() macro that tells readers and static analyzers that it should be dead code; but raises an error if executed at runtime. https://doc.rust-lang.org/std/macro.unreachable.html
* Languages with pattern-matching will either crash at compile-time if the set of clauses is non-exhaustive, or at run time if a case is missing. That is, if you don't have a catch-all clause.
if(option==1)
do_somethimg();
else
do_something_else();
...must then be rewritten as: if(option==1)
do_somethimg();
else if(option==2)
do_something_else();
else
abort();
This kind of defensive coding would have helped to prevent the famous ‘goto fail’ bug from a few years ago.