Monday, May 15, 2006


null is always a perculiar concept.
In c/c++, NULL is #defined as 0, which seems fine, as a zero pointer is always invalid.
However, in object oriented languages, especially those with garbage collection, null no longer has this meaning.
null is a special value; at once both of no type and still of every type.
For example, in C#, you can't write
if  ( null is Object )
and yet, any object can be null (we'll ignore value types).
I fully understand the need for null. It's a special flag that says there's nothing here. It's like a yes/no/unspecified thing.
It's at once an example of a broken abstraction (you can't have a value type that is null), yet at the same time overcomes a serious limitation of a binary system (having null allows a "tri-state" system, where null = unset/unspecified).
I'm loathed to say it, but I think I like the VB concept of Nothing better. Obviously, VB still has null, and it doesn't handle the difference between null, nothing and empty very well, but still, Nothing seems like a better name than null.

No comments: