null references redux + Looney Tunes

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Oct 2 07:54:27 PDT 2009


Justin Johansson wrote:
> For the interest of newsgroups readers, I dropped in at the Cafe the other day and
> the barista had this to say
> 
> http://cafe.elharo.com/programming/imagine-theres-no-null/
> 
> Disclaimer: YMMV
> 
> Cheers
> 
> -- Justin Johansson

This article brings up a very interesting point that beats Walter's 
argument to a pulp, then puts salt on it.

Walter's overriding argument (I'm sure you know it, he repeated it 
claiming nobody understands it until we learned it by heart) was: "I 
don't want the compiler to require a value there! People will just put 
some crappy value in to get the code to compile, and the code with 
errors in it will soldier on instead of duly crashing! How is that 
better???" etc.

Yet D has structs.

Walter knows D has structs, and knows how D structs operate. He put 
structs in D because he thought structs, vegetables, exercising, and 
flossing are good for you.

Yet structs operate the exact way that Walter claim is pernicious. 
Structs don't have a singular null value and always are nominally valid 
objects.

Yet I've never heard Walter continuing his argument with "Just look at 
those stinky structs. It must be a million times I had a bug caused by 
the absence of null structs! I just had to put a crappy struct there in 
my code, and my code soldiered on in error instead of crashing!"

Why didn't he continue his argument that way? And why didn't anybody 
else continue his argument that way? Because nobody has had such a 
problem. Everybody uses structs, and everybody's happy about them 
lacking null.

To complete the irony, Walter and I discussed a while ago about structs 
and .init values. We concluded that D, at least for the time being, will 
allow struct construction without any code invocation, by just 
bitcopying the .init value of the struct over. He was very happy about 
that because a lot of code generation got majorly simplified that way. 
(I was less happy because that meant less user control over struct 
construction.) So Walter was happy that he had for structs a feature he 
thinks is amazingly dangerous for classes.

So I don't think Walter's argument is invalid, I think it simply doesn't 
exist. This post made it disappear.


Andrei



More information about the Digitalmars-d mailing list