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

bearophile bearophileHUGS at lycos.com
Sat Jan 18 15:10:21 PST 2014


Walter Bright:

>> Currently you can't implement
>> "good enough" not-nullable reference types or ranged integers 
>> in D).
>
> This is not at all clear.

A good Ranged should allow syntax like this, and it should catch 
this error at compile time (with an "enum precondition"):

Ranged!(int, 0, 10)[] arr = [1, 5, 12, 3, 2];

It also should use the CPU overflow/carry flags to detect 
efficiently enough integer overflows on a Ranged!(uint, 0, 
uint.max) type. It should handle the conversions nicely to the 
super-type and allow the usage of a ranged int as array index. 
And array bound tests should be disabled if you are using a 
ranged size_t that is statically known to be in the interval of 
the array, because this is one of the main purposes of ranged 
integrals.

And D arrays should have optional strongly-typed index types, as 
in Ada. Because this makes the code safer, easier to reason 
about, and even faster (thanks to disabling some now unnecessary 
array bound tests).

Similarly not-nullable pointers and class references have some 
semantic requirements that are not easy to implement in D today.

Bye,
bearophile


More information about the Digitalmars-d mailing list