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

Why nil instead of Erlang's undefined?

Jose 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. You mention records and dictionaries but I guess you mean the process dictionary? The dict/orddict APIs don't return "undefined" afaik as well as with many other APIs (in lists for example) return a 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