Confident Code has a Zero Tolerance for Nil
31 January 2012
A transcript from a video of Avdi Grimm speaking at Mountain West RubyConf, back in November 2011 (~18:45 in):
You might have noticed a trend at this point: Going through a lot of strategies to get rid of nil.
And I really think that nil is overused in Ruby code; it represents so many things: It can mean there was an error, it can mean there was missing data, it can be a flag for default behaviour, it’s the default value for uninitialised instance variables, it’s even the default return value for conditionals when you hit the un-handled case.
As a result, I find that nil checks are the most common form of timid code.
Avdi refactors a simple demo program during the talk, to demonstrate his “zero tolerance for nil” attitude.
The result speaks for itself.