Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Byron Heads byron.heads at gmail.com
Mon May 20 08:19:40 PDT 2013


On Sun, 19 May 2013 17:36:17 -0400, Andrei Alexandrescu wrote:

> On 5/19/13 4:30 PM, Peter Alexander wrote:
>> On Sunday, 19 May 2013 at 20:03:24 UTC, Andrei Alexandrescu wrote:
>>> You are blowing it out of proportion. Null references are hardly even
>>> on the radar of the bug classes I'm encountering in the style of
>>> programming of the three groups I worked in at Facebook, and also my
>>> previous employers. People I meet at conferences and consulting gigs
>>> never mention null references as a real problem, although I very often
>>> ask about problems. I find it difficult to agree with you just to be
>>> nice.
>>
>> Just because people don't mention them as a problem doesn't mean it
>> isn't a problem.
>>
>> For what it's worth, null pointers are a real problem in the code I
>> work on (games). I don't know exactly what you work on, but I find that
>> they are more of a problem in highly stateful, interactive
>> applications. Things like generic libraries, utility programs,
>> compilers, etc. probably won't see the same problems because they
>> aren't very stateful or interactive.
>>
>> In my experience, null pointers are easy to fix, but the risk of them
>> causes people to litter their code with if (ptr) tests, often with poor
>> handling of the failure case, which can cause subtle bugs (no crash,
>> but unintended code path).
>>
>> Just my 2c.
> 
> OK, this is sensible. One question - would you be willing to type
> symbols as NullType!T instead of T to avoid these issues?
> 
> Thanks,
> 
> Andrei

More boiler plate code for functions that take pointers.

void foo(T)(T t)
	if(isPointer!T)
{
    static if(isNullable!T)
	if(!t) throw ....
}

May also introduce then need to check for objects in the init state 
(default state)



outside of NonNull in stdlib, an attribute maybe a possible answer.

void bar(@nonnull SomeClass o)
{
	o = foo(); // if foo returns @nonnull, then check is not needed, 
else needs a check added during assignment
}

there are a few compile time checks that can be done to prove o is not 
null, if not the compiler adds runtime checks.

But really, checking for valid input is part of programming, might be 
better to have lint integration that can help find these types of problems



More information about the Digitalmars-d mailing list