是否有没有"null"的语言? [英] Are there languages without "null"?
问题描述
许多人认为特殊值null
的概念(因为它在C,Java,C#,Perl,Javascript,SQL等语言中使用)是一个坏主意.在SO和P.SE上存在一些与此有关的问题,例如没有语言的最佳解释空和空引用真的是一件坏事吗?.
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? .
但是,没有它们,我找不到任何语言.我熟悉的所有语言都具有null
或类似的语言(例如,Perl中的未定义").
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).
我意识到,实际上每种语言都需要某种方式来表达缺乏价值".但是,也可以使用 Optional
(番石榴).与具有"null"或"undefined"的主要区别在于,如果对象具有特定类型(也许,可选...),则只能具有无值".相反,空"/未定义"通常是每种类型可能的有效值.
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.
在这种意义上是否有没有空"或类似概念的语言?
推荐答案
以下是您所描述的不包含null
/undefined
/nothing
的语言的不完整列表,根据维基百科的出现年份进行排序
Here's an incomplete list of languages without null
/ undefined
/ nothing
in the sense you described, ordered by year of first appearance according to Wikipedia.
- C#8将具有可为空的引用类型.
- 序言.逻辑变量代表一切".没有空"或未定义"的概念.
- Pony (低于1.0.0).使用联合类型,其中类型之一是
None
. - 水晶(处于alpha阶段):确实具有
nil
,但在编译时会阻止所有空指针异常时间. - 科林(2015年):具有采用
?
语法的可选类型. - Swift (2014年):具有采用
?
语法的可选类型. - Hack (2014年):具有采用
?
语法的可选类型. - TypeScript (2012年):联合类型可以将
undefined
或null
作为变体. - Elm (2012年):联合类型为
Maybe
. - 锡兰(2011):具有采用
?
语法的可选类型. - Rust (2010年):具有可选类型
Option
. - 幻想(2005年):具有采用
?
语法的可选类型. - F#(2005年):联合类型为
Option
. - 尼斯(2003年):具有采用
?
语法的可选类型. - Netlogo (1999)没有输入
null
- OCaml (1996年):联合类型为
option
. - Haskell (1990年):联合类型为
Maybe
. - 标准ML (1990年):联合类型为
option
. - Tcl (1988)
- Erlang (1986)
- C# 8 will have nullable reference types.
- Prolog. A logical variable stands for "anything at all". There is no concept of "null" or "undefined".
- Pony (pre-1.0.0). Uses union type where one of the types is
None
. - Crystal (in alpha stage): Does have
nil
, but prevents all null pointer exceptions at compile-time. - Kotlin (2015): Has optional types with
?
syntax. - Swift (2014): Has optional types with
?
syntax. - Hack (2014): Has optional types with
?
syntax. - TypeScript (2012): Has union types that can have
undefined
ornull
as a variant. - Elm (2012): Has union type
Maybe
. - Ceylon (2011): Has optional types with
?
syntax. - Rust (2010): Has optional type
Option
. - Fantom (2005): Has optional types with
?
syntax. - F# (2005): Has union type
Option
. - Nice (2003): Has optional types with
?
syntax. - Netlogo (1999) has no type
null
- OCaml (1996): Has union type
option
. - Haskell (1990): Has union type
Maybe
. - Standard ML (1990): Has union type
option
. - Tcl (1988)
- Erlang (1986)
随时补充清单.
这篇关于是否有没有"null"的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!