Null references (oh no, not again!)

Christopher Wright dhasenan at gmail.com
Wed Mar 4 03:57:09 PST 2009


Walter Bright wrote:
> Rainer Deyke wrote:
>> Writing an assertion for every non-nullable reference argument for every
>> function is tedious.
> 
> It's also quite unnecessary. The hardware will do it for you, and the 
> debugger will tell you where it is.
> 
> The hardware won't help you with array overflows or uninitialized 
> variables, however.

The hardware will catch it when you try to use a null pointer. It does 
nothing for you when you store null in a pointer that's supposed to be 
valid.

In order for you to make sure you don't store null somewhere you can't 
have null, you need to add an invariant to that effect, make that field 
private, and always access it via public properties.

And you can't compile with -release.

This is only a problem with complex data structures, usually, I think.

I'd like to try non-nullable by default, but there are a number of 
issues that would have to be resolved that seriously affect their 
usability. Also, I don't like the opportunity cost of asking Walter to 
implement this feature.



More information about the Digitalmars-d mailing list