Implications of not including NULL in a language?

后端 未结 10 1315
广开言路
广开言路 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:12

    Interesting discussion happening here.

    If I was building a language, I really don't know if I would have the concept of null. I guess it depends on how I want the language to look. Case in point: I wrote a simple templating language whose main strength is nested tokens and ease of making a token a list of values. It doesn't have the concept of null, but then it doesn't really have the concept of any types other than string.

    By comparison, the langauge it is built-in, Icon, uses null extensively. Probably the best thing the language designers for Icon did with null is make it synonymous with an uninitialized variable (i.e. you can't tell the difference between a variable that doesn't exist and one that currently holds the value null). And then created two prefix operators to check null and not-null.

    In PHP, I sometimes use null as a 'third' boolean value. This is good in "black-box" type classes (e.g. ORM core) where a state can be True, False or I Don't Know. Null is used for the third value.

    Of course, both of these languages do not have pointers in the same way C does, so null pointers do not exist.

提交回复
热议问题