Is the other-kind-of-null really necessary in Nullable and Variant?
bearophile
bearophileHUGS at lycos.com
Sun Apr 28 10:02:56 PDT 2013
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
More information about the Digitalmars-d
mailing list