logoalt Hacker News

cowlevel • yesterday at 10:02 PM • 1 reply • view on HN

Code with the necessary level of defense isn't defensive code, it's just code. It becomes defensive when you add too much defense. Like C programmers writing if(!ptr) return -EBADPTR; at the start of every function instead of just letting it crash.

(Yes it's technically undefined behaviour and not guaranteed to crash. In practice, an errant null does crash, producing a much more debuggable symptom than an ignored error code, and we are writing code for real compilers that actually exist.)


Replies

AnimalMuppet • yesterday at 10:23 PM

Depends on what it's code for. For aircraft software, "just letting it crash" can be unpleasantly literal.

➕ show 1 reply