Null references redux
Jeremie Pelletier
jeremiep at gmail.com
Sat Sep 26 21:57:04 PDT 2009
Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Justin Johansson wrote:
>>> Walter, in the heat of this thread I hope you haven't missed the
>>> correlation with discussion
>>> on "Dispatching on a variant" and noting:
>>
>> Thanks for pointing it out. The facilities in D enable one to
>> construct a non-nullable type, and they are appropriate for many designs.
>
> No. There is no means to disable default construction.
>
>> I just don't see them as a replacement for *all* reference types.
>
> Non-nullable references should be the default.
>
>
> Andrei
Like I said in another post of this thread, I believe the issue here is
more over initializer semantics than null/non-null references. This is
what's causing most of the errors anyways.
Can't the compiler just throw a warning if a variable is used before
initialization, and allow "= null" to bypass this ("= void" would still
be considered uninitialized). Same thing for fields.
It would be much more convenient than new type variants, both to
implement and to use.
It could even be used for any type, the default initializer in D is a
cute idea, but not a performance friendly one. I would much prefer the
compiler to allow "int a" but warn me if I use it before assigning
anything to it than assigning it to zero, and then assigning it to the
value I wanted. "= void" is nice but I'm pretty sure I'm way over a
thousand uses of it so far.
Jeremie
More information about the Digitalmars-d
mailing list