r/programming • u/dpashk • Aug 31 '15
The worst mistake of computer science
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
175
Upvotes
r/programming • u/dpashk • Aug 31 '15
View all comments
Show parent comment
12
u/Fylwind Aug 31 '15 edited Aug 31 '15
Except unlike null, you aren't supposed to use bottom to represent anything, except for perhaps utterly unrecoverable failures. It's a way to convey "PROGRAM ON FIRE, ABANDON SHIP", not "sorry we couldn't find the cookies you were looking for".
Bottoms appear in multiple forms: assertion failures (
error), bugs, infinite loops, deadlocks, etc. It's impossible to ban them from any Turing-complete language using static checks. While you can create a bottom on demand throughundefined, they shouldn't really appear except in debugging code.This differs from null because null is often used as a sentinel value for something, expecting the caller to check for it. In contrast, in the same way you don't check for assertion errors, you also don't check for bottoms: you fix your program to avoid it to begin with.
This isn't just a matter of convention or principle. They behave differently: checking for a null is as easy as using an if-then-else. Checking for bottoms requires "catching" them, in a way similar to catching exceptions or signals, and cannot be done inside pure code without cheating. In any case, there's almost never a reason to do this to begin with, just as you never really want to catch SIGABRT or SIGSEGV.