null [re: spec#]

foobar foo at bar.com
Sat Nov 6 03:22:12 PDT 2010


1. the INVENTOR of the "reference" concept himself admits that this is a flawed design. 
see:  http://qconlondon.com/london-2009/presentation/Null+References:+The+Billion+Dollar+Mistake

2. "null" is an a type-system attribute, hence should be checked at compile time and would have ZERO affect on run-time performance. 
Same as assigning a string value to an int variable. 

3. the notion of an "undefined" state for a type can be generally implemented by the OPTION type and D pointers are an ad hoc implementation of this concept.
see: http://en.wikipedia.org/wiki/Option_type
Any type can be wrapped by an OPTION type. trying to do the converse of this is impractical and is bad design. 

4. As already pointed by others, Walter's array should be:
Option!T[] array; 

5. C programmers use null pointers and other special "canary" values as Walter described mainly as rcodes. This is a BAD and bug-prone way of handling errors and is replaced in D by a MUCH better mechanism called "Exceptions". I do NOT want to check for null or zero or NaN throughout my code as if I'm writing c code! This is why D uses signaling NaNs for floats. 
This accounts for the majority of the uses of null. For the rest just use the option type!


More information about the Digitalmars-d mailing list