3 ms·
Even in a language that has a relatively rich syntax, like Ruby, treating nil as false can make code more concise and understandable. For example: hash[key
by weavejester 16y ago
Even in a language that has a relatively rich syntax, like Ruby, treating nil as false can make code more concise and understandable. For example:
hash[key] = value if !hash[key].nil?
Can be written as:
hash[key] ||= value
And:
response = find_resource(key)
response.nil? ? response : not_found
Can be written as:
find_resource(key) or not_found
I also can't think of any instance where a function has used an empty string to denote a failure condition. In a language that treats nil as being false, generally functions are quite careful as to the value they return.