Skip to content
josevalim edited this page Nov 27, 2012 · 38 revisions

Why nil instead of Erlang's undefined?

José Valim:

I would have chosen undefined instead of nil if it was actually a recurrent pattern in Erlang APIs but the truth is that it isn't. Some APIs like records and process dictionaries do return undefined, but the majority of them (dict, orddict, lists, etc) APIs don't return undefined but rather false or a tuple.

Someone already asked me why not make the || operator work on tuples like { :error, _ } so we can easily wrap Erlang code without nil. It is basically the same idea of using something else Erlang already returns instead of nil.

That said, I believe the undefined cases to be few so I chose to go with a terminology which is shorter and more known by developers (nil or null) instead of undefined.

Clone this wiki locally