Current sentiment on Nullable.get
Sebastiaan Koppe
mail at skoppe.eu
Mon Dec 17 08:05:30 UTC 2018
On Sunday, 16 December 2018 at 23:13:32 UTC, aliak wrote:
> On Saturday, 15 December 2018 at 15:44:25 UTC, Jonathan M Davis
> wrote:
>> auto foo(T t)
>> {
>> ...
>> if(member.isNull)
>> member = t;
>> bar(member.get);
>> ...
>> }
>>
>> If T were a class or pointer, and t were null, then that code
>> would fail the assertion in get if nullable types were treated
>> differently.
>
> Yes. You're accessing get without checking isNull first. Bad
> code, bad practice, should not pass code review. Not sure I see
> how that's a bad thing.
Agreed. Normally one would do either:
member.orElse(t).map!(bar); // or
member.withDefault(t).map!(bar);
> Sounds like you want a type that's called HasBeenAssignTo. Not
> an optional type.
Yep, that seems to be the source of our differences. My idea of
Nullable has always been that it is exactly like Optional, but it
is not.
It might be a good idea to update the docs to reflect that.
More information about the Digitalmars-d
mailing list