There are many people who think that the concept of the special value null
(as it is used in lanuages like C, Java, C#, Perl, Javascript, SQL etc.) is a bad idea. There are several questions about this on SO and P.SE, such as Best explanation for languages without null and Are null references really a bad thing? .
However, I could not find any language that does without them. All the languages I'm familiar with have null
, or something similar (e.g. "undefined" in Perl).
I realize that proably every language needs some way to express "absence of a value". However, instead of having "null" or "undefined", this can also be made explicit by using something like Maybe
(Haskell) or Optional
(Guava). The principal difference to having "null" or "undefined" is that an object can only have "no value" if it has a specific type (Maybe, Optional...). In contrast, "null"/"undefined" is typically a valid value possible for every type.
Are there any languages that do not have null
or a similar concept in this sense?
Maybe
in Haskell, orOptional
in Guava. I'll edit the question. – Merceexists
. See perldoc.perl.org/functions/exists.html – GribbleMaybe
. Also, Haskell has Bottom, which seems similar toundefined
in other languages. – Merceundefined
, because you can't for example have a function that returnsTrue
if its parameter is bottom andFalse
otherwise. It's basically a lazy exception: if a function tries to look at it, it also has to return bottom itself. (I think.) – Cappellanull
or much of anything really. – Joletta