A few questions

bearophile bearophileHUGS at lycos.com
Fri Jul 27 20:07:44 PDT 2012


Jonathan M Davis:

>> // x is a nullable class reference
>> if (x == null) {
>>      ...
>> } else {
>>      // here the type system sees x as not null.
>> }
>
> ??? What does it matter if the type system knows whether a 
> pointer is null
> unless it's trying to warn you about dereferencing null?

In the else branch the state of the type of x is not-null, so as 
example in the else branch you are allowed to call a function 
that only accept not null references, with the x variable.
Not-nulls integrated in the type system makes sure you have well 
initialized variables in the class constructors in presence of 
inheritance and other complexities.
It also statically requires you to test for null before 
deferencing a nullable class reference, ans so on.
Those are the fruits that a good not-null implementation gives 
you. You can't do all this with the NotNull toy. NotNull solves 
only the easy part of the whole problem, and it's a small part.


> Actually, it is. I said "that I'm aware of."

Right :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list