Null references redux

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Sep 26 14:43:58 PDT 2009


On Sat, Sep 26, 2009 at 5:29 PM, Jeremie Pelletier <jeremiep at gmail.com> wrote:

> I actually side with Walter here. I much prefer my programs to crash on
> using a null reference and fix the issue than add runtime overhead that does
> the same thing. In most cases a simple backtrace is enough to pinpoint the
> location of the bug.

There is NO RUNTIME OVERHEAD in implementing nonnull reference types.
None. It's handled entirely by the type system. Can we please move
past this?

> Null references are useful to implement optional arguments without any
> overhead by an Optional!T wrapper. If you disallow null references what
> would "Object foo;" initialize to then?

It wouldn't. The compiler wouldn't allow it. It would force you to
initialize it. That is the entire point of nonnull references.



More information about the Digitalmars-d mailing list