Non-null objects, the Null Object pattern, and T.init

Timon Gehr timon.gehr at gmx.ch
Sat Jan 18 23:56:06 PST 2014


On 01/18/2014 10:05 PM, Walter Bright wrote:
> On 1/17/2014 7:05 AM, Michel Fortin wrote:
>> Some more thoughts.
>
> The postfix ? has parsing issues with ?: expressions.
> ...

In what sense? It can be unambiguously parsed easily.

> Aside from that, non-null is only one case of a universe of types that
> are subsets of other types.

This is not true. The main rationale for "non-null" is to eliminate null 
dereferences. A? in his proposal is different from current nullable 
references in that the compiler does not allow them to be dereferenced.

If we just had a solution for arbitrary subset types, we'd _still_ be 
left with a type of references that might be null, but are not prevented 
to be dereferenced.


Besides, I think it is strange to think of valid references as just 
being some arbitrary special case of nullable references. A nullable 
reference is roughly what you get when you put an arbitrary incompatible 
value 'null' into the set of valid references:

{valid references} ∪ {null}

All that is asked for is to make the disjunct that is _actually 
interesting_ it's own type. Sure, it could be described as:

{x ∈ ({valid references} ∪ {null}) | x ≠ null}

But I think this is a silly way of expressing oneself.

> I'd prefer a more general solution.
>

Subset types are not more general than the proposed feature.


More information about the Digitalmars-d mailing list