Reference counted containers prototype

deadalnix deadalnix at gmail.com
Tue Dec 27 08:43:50 PST 2011


Le 27/12/2011 16:04, Andrei Alexandrescu a écrit :
> On 12/27/11 5:32 AM, deadalnix wrote:
>> The first thing that I see looking at the source code is how many null
>> check you'll find in RefCounted . As the RefCounted struct is useless
>> without a payload, we should ensure that the payload exists, in all
>> cases, and not null check at every operation.
>
> D's take on default constructor makes it impossible to initialize the
> object 100% automatically. What can be done is a test inside opDispatch
> followed by default construction if the object is null. That's not
> terribly useful and intuitive. Consider:
>

That is just moving the problem around. It is even worse I think.

>
> This is the behavior of any reference type that can be null, because
> null doesn't refer to any object. IMHO this, and not null pointer
> exceptions, is the largest liability of null.
>
>
> Andrei

Yes, the problem is way larger. I think null is a very poor solution to 
a real instanciation problem. This cause more trouble than solution. It 
is error prone (forget a null check and you are doomed) and have a 
runtime cost.


More information about the Digitalmars-d mailing list