What would we do without NULL?

后端 未结 11 932
迷失自我
迷失自我 2021-02-01 05:26

I once read that having nullable types is an absolute evil. I believe it was in an article written by the very person who created them(in Ada?) I believe this is the article

11条回答
  •  花落未央
    2021-02-01 05:58

    You can adopt a simple rule: All variables are initialized (as a default, this can be overridden) to a immutable value, defined by the variable's class. For scalars, this would usually be some form of zero. For references, each class would define what its "null" value is, and references would be initialized with a pointer to this value.

    This would be effectively a language-wide implementation of the NullObject pattern: http://en.wikipedia.org/wiki/Null_Object_pattern So it doesn't really get rid of null objects, it just keeps them from being special cases that must be handled as such.

提交回复
热议问题