| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
March 05, 2009 Re: Null references (oh no, not again!) | ||||
|---|---|---|---|---|
| ||||
bearophile Wrote:
> Andrei Alexandrescu:
> > I did some more research and found a study:
> > http://users.encs.concordia.ca/~chalin/papers/TR-2006-003.v3s-pub.pdf
> > ...
> > Turns out in 2/3 of cases, references are really meant to be non-null...
> > not really a landslide but a comfortable majority.
>
> Thank you for bringing real data to this debate.
> Note that 2/3 is relative to nonlocal variables only:
>
> >In Java programs, at least 2/3 of declarations (other than local variables) that are of
> reference types are meant to be non-null, based on design intent.
> We exclude local variables because their non-nullity can be inferred by intra-procedural
> analysis<
>
> So the total percentage may be different (higher?).
> Anyway, nonnullable by default seems the way to go if such feature is added.
>
I think there is some faulty logic here.
People are writing code that has a design intention of nullable (as shown in the study) precisly because that is the default reference type in the language.
Inferring that the default for a new language should be nullable based on these statistics would be a logical error.
Implementing default non nullable would have the effect of reducing the amount of design intentional nullable used. It would also greatly increase the quality and maintainability of the code, as all references not specifically marked as nullable could be safely dereferenced.
Alex
| ||||
March 05, 2009 Re: Null references (oh no, not again!) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alex Burton | Alex Burton Wrote:
> bearophile Wrote:
>
> > Andrei Alexandrescu:
> > > I did some more research and found a study:
> > > http://users.encs.concordia.ca/~chalin/papers/TR-2006-003.v3s-pub.pdf
> > > ...
> > > Turns out in 2/3 of cases, references are really meant to be non-null...
> > > not really a landslide but a comfortable majority.
> >
> > Thank you for bringing real data to this debate.
> > Note that 2/3 is relative to nonlocal variables only:
> >
> > >In Java programs, at least 2/3 of declarations (other than local variables) that are of
> > reference types are meant to be non-null, based on design intent.
> > We exclude local variables because their non-nullity can be inferred by intra-procedural
> > analysis<
> >
> > So the total percentage may be different (higher?).
> > Anyway, nonnullable by default seems the way to go if such feature is added.
> >
> I think there is some faulty logic here.
>
> People are writing code that has a design intention of nullable (as shown in the study) precisly because that is the default reference type in the language.
>
> Inferring that the default for a new language should be nullable based on these statistics would be a logical error.
>
> Implementing default non nullable would have the effect of reducing the amount of design intentional nullable used. It would also greatly increase the quality and maintainability of the code, as all references not specifically marked as nullable could be safely dereferenced.
>
> Alex
Oops I'm wrong the 2/3 is NON nullable. My brain seems to have trouble reading all this 'non null' stuff.
| |||
March 05, 2009 Re: Null references (oh no, not again!) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alex Burton | Alex Burton Wrote:
>
> Oops I'm wrong the 2/3 is NON nullable. My brain seems to have trouble reading all this 'non null' stuff.
>
Actually non nullable is a double negative.
What we really want in the D language and the language of the discussions about D is simple.
1) Types.
2) Nullable Types - optional
There is no need for Non Nullable types. These are Types.
Alex
| |||
March 05, 2009 Re: Null references (oh no, not again!) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alex Burton | Alex Burton escribió: > Alex Burton Wrote: > > >> Oops I'm wrong the 2/3 is NON nullable. My brain seems to have trouble reading all this 'non null' stuff. >> > Actually non nullable is a double negative. > > What we really want in the D language and the language of the discussions about D is simple. > > 1) Types. > > 2) Nullable Types - optional > > There is no need for Non Nullable types. These are Types. I think nullable types can't be optional. How do you implement a linked list without them? You use a dummy value for the "no next node"? Naaah... > > Alex | |||
March 05, 2009 Re: Null references (oh no, not again!) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ary Borenszweig | Ary Borenszweig wrote: > I think nullable types can't be optional. How do you implement a linked list without them? You use a dummy value for the "no next node"? Naaah... A nullable type is, conceptually, a container that can contain either zero or one element. If there was no language or library support for nullable types, you could always use a dynamic array or some othet container instead. -- Rainer Deyke - rainerd@eldwood.com | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply