Null references (oh no, not again!)

Don nospam at nospam.com
Wed Mar 4 00:40:00 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.
> 
In most of my experience, #2 is a special case of #4.
The worst case for an uninitialized variable is when it's a pointer; the 
best value (by far) that such an a uninitialized pointer can have is null.
OTOH I find that null references are an order of magnitude more common 
in D than in C++. I think that's significant, because in my experience, 
it's the only category of bugs which is worse in D.
It's far too easy to declare a class and forget to 'new' it.



More information about the Digitalmars-d mailing list