是否有没有"null"的语言? [英] Are there languages without "null"?

查看:125
本文介绍了是否有没有"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).

我意识到,实际上每种语言都需要某种方式来表达缺乏价值".但是,也可以使用 (Haskell)或 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年):联合类型可以将undefinednull作为变体.
  • 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 or null 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆