digitalmars.D - Re: Null references (oh no, not again!)
- Alex Burton <alexibu mac.com> Mar 05 2009
- Alex Burton <alexibu mac.com> Mar 05 2009
- Alex Burton <alexibu mac.com> Mar 05 2009
- Ary Borenszweig <ary esperanto.org.ar> Mar 05 2009
- Rainer Deyke <rainerd eldwood.com> Mar 05 2009
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
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.
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
Mar 05 2009
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
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.
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.
Mar 05 2009
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.
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
Mar 05 2009
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.
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
Mar 05 2009
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
Mar 05 2009