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?
Here's an incomplete list of languages that are null-safe in the sense that they don't have any non-nonnullable types:
?
syntax.?
syntax.None
.?
syntax.nil
, but prevents all null pointer exceptions at compile-time.?
syntax.undefined
or null
as a variant.Maybe
.?
syntax.Option
.?
syntax.Option
.?
syntax.null
option
.Maybe
.option
.Feel free to complement the list. The years represent the first public release.