Null references redux
Christopher Wright
dhasenan at gmail.com
Sat Sep 26 17:02:51 PDT 2009
Walter Bright wrote:
> Denis Koroskin wrote:
>> If an object may or may not have a valid value, you mark it as
>> nullable. All the difference is that it's a non-default behavior,
>> that's it. And a user is now warned, that an object may be not
>> initialized.
>
> He isn't warned, that's just the problem. The null object happily says
> "I succeeded" for all input and returns more default values and null
> objects.
This is not the proposal. The proposal was to codify in the type system
whether a particular object has "null" as a valid value. If a variable
that cannot be null is not initialized to a non-null value before use,
that is an error.
It's entirely equivalent to using the current type system with a ton of
manual contracts requiring that variables not be null. Except the
contracts are enforced at compile time, not runtime.
A similar concept would be range-bounded integer types, or floating
point types that cannot be NaN or infinity.
More information about the Digitalmars-d
mailing list