The new ?? and ??? operators
renoX
renosky at free.fr
Sun Sep 23 12:27:49 PDT 2007
Arlen Albert Keshabyan a écrit :
> It would be the sugar syntactic to add '??' operator to D. Consider
> the example code:
>
> string error_message = getErrorMessage() ?? "no errors"; A a =
> x.getPreparedAObject() ?? y.getPreparedAObject() ?? new A();
>
> This operator is supposed to do the same thing as C# does: lvalue
> evaluates to the first non-null value or to null if all rvalues
> contains null.[cut]
I feel as if the ?? operator is a workaround for the real issue, the
fact that types reference can be null by default.
In Nice by default, types are not nullable so you don't need to put null
tests everywhere and there's a nice syntax for nullable type: just
append a '?' to your type name i.e:
Type x = ...; // Here you're sure that x can never be null.
Type? x; // x may be null.
This is a big change, but it feels "more right" to me.
renoX
More information about the Digitalmars-d
mailing list