References in D

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 15 10:52:19 PDT 2012


On Saturday, September 15, 2012 19:35:44 Alex Rønne Petersen wrote:
> Out of curiosity: Why? How often does your code actually accept null as
> a valid state of a class reference?

I have no idea. I know that it's a non-negligible amount of the time, though 
it's certainly true that they normally have values. But null is how you 
indicate that a reference has no value. The same goes for arrays and pointers. 
Sometimes it's useful to have null and sometimes it's useful to know that a 
value can't be null. I confess though that I find it very surprising how much 
some people push for non-nullable references, since I've never really found 
null to be a problem. Sure, once in a while, you get a null pointer/reference 
and something blows up, but that's very rare in my experience, so I can't help 
but think that people who hit issues with null pointers on a regular basis are 
doing something wrong.

- Jonathan M Davis


More information about the Digitalmars-d mailing list