4 ms·
Cool language feature! I’ve done this in other languages using a code style policy where all “naked” else statements and ‘default’ inside a switch statement mus
by ryandrake 7y ago
Cool language feature! I’ve done this in other languages using a code style policy where all “naked” else statements and ‘default’ inside a switch statement must throw an uncaught exception or otherwise deliberately crash.
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.