On Sunday, 28 April 2013 at 17:02:57 UTC, bearophile wrote:
Idan Arye:

When you use `std.typecons.Nullable` with a type that already accept `null` values, you get two types of nulls - the `Nullable`'s null state the the regular type's `null`:

   Nullable!string a;
   writeln(a.isNull()); //prints "true"
   a = null;
   writeln(a.isNull()); //prints "false"

Originally D dynamic arrays were almost conflated with regular pointers (they were seen as fat pointers). This was recently partially fixed (so assigning a pointer to a dynamic array is now forbidden), but accepting "null" for their empty literal is one left part of that original suboptimal design.

Time ago I have proposed to forbid "null" as literal for an empty dynamic array literal, an empty associative literal, or an empty string, and to accept only [] "" [:] (D already has the first two literals and the third looks natural).

See also:
http://d.puremagic.com/issues/show_bug.cgi?id=3889
http://d.puremagic.com/issues/show_bug.cgi?id=5788
http://d.puremagic.com/issues/show_bug.cgi?id=7227

Bye,
bearophile

I used `Nullable!string` for the example, but it could just as easily be `Nullable!Object` or `Nullable!(int*)`.

Reply via email to