Null references redux
Jeremie Pelletier
jeremiep at gmail.com
Sun Sep 27 12:42:02 PDT 2009
Jarrett Billingsley wrote:
> On Sun, Sep 27, 2009 at 2:07 PM, Jeremie Pelletier <jeremiep at gmail.com> wrote:
>
>>> Yes and no. It introduces an "if" statement for null checking, but only
>>> for nullable references. If you know your reference can't be null it should
>>> be non-nullable, and then you don't need to check.
>> I much prefer explicit null checks than implicit ones I can't control.
>
> Nonnull types do not create implicit null checks. Nonnull types DO NOT
> need to be checked. And nullable types WOULD force explicit null
> checks.
Forcing checks on nullables is just as bad, not all nullables need to be
checked every time they're used.
>> What about non-nan floats? Or non-invalid characters? I fear nonnull
>> references are a first step in the wrong direction. The focus should be
>> about implementing variable initialization checks to the compiler, since
>> this solves the issue with any variable, not just references. The flow
>> analysis can also be reused for many other optimizations.
>
> hash_t foo(Object o) { return o.toHash(); }
> foo(null); // bamf, I just killed your function.
>
> Forcing initialization of locals does NOT solve all the problems that
> nonnull references would.
You didn't kill my function, you shot yourself in the foot. Something
trivial to debug.
More information about the Digitalmars-d
mailing list