Avoid Nil, Unless You Mean It
Most languages we’ve used have had the concept of a null reference, like Objective-C’s nil. They’ve also famously been called a Billion Dollar Mistake.[16] The main problem with nil is that it’s usually an exceptional condition. A variable contains, or a function returns, either something useful or nil. How are we supposed to interpret nil? Does it mean that there is no data? Does it mean there was an error? Languages usually don’t help us here. We’re left to clutter our code with defensive if statements, or forget to do that and track down strange errors later.
Maybe this isn’t technically a functional feature, but it is part of your functional thinking toolkit. Functional languages typically have a way to explicitly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access