null dereference exception vs. segfault?
Pelle
pelle.mansson at gmail.com
Mon Aug 2 15:21:13 PDT 2010
On 08/03/2010 12:02 AM, bearophile wrote:
> Pelle:
>> What I really wish for is non-nullable types, though. Maybe in D3... :P
>
> I think there is no enhancement request in Bugzilla about this, I will add one.
I think there has been, at least this has been discussed on the newsgroup.
> To implement this you have to think about the partially uninitialized objects too, this is a paper about it, given a class type T it defines four types (I think the four types are managed by the compiler only, the programmer uses only two of them, nullable class references and nonnullable ones):
> http://research.microsoft.com/pubs/67461/non-null.pdf
>
> If a language defaults to nonnullable references, then you can use this syntax:
>
> class T {}
> T nonnullable_instance = new T;
> T? nullable_instance;
>
> But now it's probably nearly impossible to make D references nonnullable on default, so that syntax can't be used. And I don't what syntax to use yet. Suggestions welcome.
>
> Bye,
> bearophile
That is a good syntax indeed. What is also needed is a way of
conditionally getting the reference out of the nullable.
I think delight uses something like this:
T? nullable;
if actual = nullable:
actual.dostuff;
I think a good thing would be NonNull!T, but I haven't managed to create
one. If this structure exists and becomes good practice to use, maybe we
can get the good syntax in D3. In 20 years or so :P
More information about the Digitalmars-d-learn
mailing list