Current sentiment on Nullable.get
Rubn
where at is.this
Sat Dec 15 12:33:04 UTC 2018
On Saturday, 15 December 2018 at 04:06:55 UTC, Jonathan M Davis
wrote:
> On Friday, December 14, 2018 8:26:17 PM MST Rubn via
> Digitalmars-d wrote:
>> As a side note you could also easily add a separate function
>> that would do what you are suggesting:
>>
>> bool hasValue() const;
>>
>> which wouldn't check if the value is null (for naturally
>> nullable types). Now, tell me, what would you name the
>> function to check if the value is null, including for
>> naturally nullable types if you wanted to add it to the
>> current Nullable struct ? What would you name that function to
>> make it obvious to a read at first glance that that is how it
>> functions.
>
> Changing the behavior of Nullable would silently break existing
> code. So, regardless of whether Nullable's current behavior is
> desirable, simply changing its behavior is completely
> unacceptable.
>
> And if we were designing Nullable from scratch, trying to make
> the names involved clearer in the process, then it would
> probably just be something like Optional, with isEmpty or
> hasValue being the function use to check whether it contained
> anything rather than isNull. Either way, as I keep pointing
> out, for it to be possible to reliably use it in generic code,
> it needs its current semantics, and having it treat nullable
> types differently makes it pointless to use it outside of
> generic code. As such, having a Nullable/Optional type which
> treats pointers differently just makes no sense.
>
> But if you want that, as I understand it, you can find at least
> one library on code.dlang.org that has defined its own Optional
> type which works that way.
>
> - Jonathan M Davis
I'm not arguing that Optional isn't a useful type, but if you are
going to fix the problems with deprecating the "alias this get;"
then you are going to be breaking just as much code. You might as
well deprecate the entire class and add one that is called
Optional. And you feel such a class called Nullable that does
what the name suggestions isn't useful. Then don't readd the type
once it has been deprecated and removed.
More information about the Digitalmars-d
mailing list