Null references redux

Tom S h3r3tic at remove.mat.uni.torun.pl
Sat Sep 26 18:48:17 PDT 2009


Andrei Alexandrescu wrote:
> [snip]
> The problem is you keep on insisting on one case "I have a non-null 
> reference that I don't have an initializer for, but the compiler forces 
> me to find one, so I'll just throw a crappy value in." This focus on one 
> situation comes straight with your admitted bad habit of defining 
> variables in one place and initializing in another. The situation you 
> need to open a curious eye on is "I have a reference that's never 
> supposed to be null, but I forgot about initializing it and the compiler 
> silently put a useless null in it." The simplest case is what _every_ D 
> beginner has done:
> 
> T x;
> x.fun();
> 
> to witness a crash. Why the hell does that crash? It did work when T was 
> a struct. (Also this damns generic code to hell.)
> 
> So again: focus on the situation when people forget to initialize 
> references that are never supposed to be null.
> 
> That has happened to me, and I'm supposed to know about this stuff. And 
> one thing you don't understand is that on Linux, access violations are 
> much more difficult to figure than others. On a computing cluster it 
> gets one order of magnitude more difficult. So spare me of your Windows 
> setup that launches your debugger on the line of the crash. For better 
> or worse, many don't have that. People sometimes have problems that you 
> don't have, and you need to put yourself in their shoes.

Quoted for truth.


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d mailing list