O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required