Are there languages without “null”?

后端 未结 3 518
误落风尘
误落风尘 2021-02-06 23:55

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. T

3条回答
  •  野的像风
    2021-02-07 00:36

    Here's an incomplete list of languages that are null-safe in the sense you described:

    • 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)

    Feel free to complement the list. The year represents the first appearance according to Wikipedia.

提交回复
热议问题