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

Walter Bright newshound2 at digitalmars.com
Sat Jan 18 15:15:42 PST 2014


On 1/18/2014 3:10 PM, bearophile wrote:
> 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).

While these are all desirable features, it is not clear that these cannot be 
implemented without changing the language - for example, improved optimization 
can do a lot.

And secondly, you said "good enough" not "perfect". Even putting things into the 
language does not imply they will be perfect, as experience amply shows.


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

For example?



More information about the Digitalmars-d mailing list