Implications of not including NULL in a language?

后端 未结 10 1355
广开言路
广开言路 2020-12-28 19:38

I know that NULL isn\'t necessary in a programming language, and I recently made the decision not to include NULL in my programming language. Declaration is done by initial

10条回答
  •  醉话见心
    2020-12-28 20:04

    In my mind there are two uses cases for which NULL is generally used:

    • The variable in question doesn't have a value (Nothing)
    • We don't know the value of the variable in question (Unknown)

    Both of common occurrences and, honestly, using NULL for both can cause confusion.

    Worth noting is that some languages that don't support NULL do support the nothing of Nothing/Unknown. Haskell, for instance, supports "Maybe ", which can contain either a value of or Nothing. Thus, commands can return (and accept) a type that they know will always have a value, or they can return/accept "Maybe " to indicate that there may not be a value.

提交回复
热议问题