Open question: what code pattern you use usually for null safety problem
ddcovery
antoniocabreraperez at gmail.com
Fri Jan 15 18:04:56 UTC 2021
On Friday, 15 January 2021 at 14:25:09 UTC, Steven Schveighoffer
wrote:
> On 1/15/21 9:19 AM, Steven Schveighoffer wrote:
>
>> Something similar to BlackHole or WhiteHole. Essentially
>> there's a default action for null for all
>> types/fields/methods, and everything else is passed through.
>
> And now reading the other thread about this above, it looks
> like this type is already written:
>
> https://code.dlang.org/packages/optional
>
> I'd say use that.
>
> -Steve
Yes, the Optional/Some/None pattern is the "functional"
orientation for avoiding the use of "null".
Swift uses a similar pattern (and scala too) and supports the
"null safety operators" ?. and ?? (it doesn't work on "null"
but on optional/nil).
The more I think about it, the more fervent defender of the use
of ?. and ?? I am.
The misinterpretation about "null safety" is we talk about "null"
reference safety, but this pattern can be used with "optional"
to...
D has not optional/none/some native implementation and this is
the reason we think about "?." as a "bad pattern" because we
imagine it is for "null" values exclusively.
But like other operators, they could be overloaded and adapted to
each library.
Well, I'm digressing: good night!!!
More information about the Digitalmars-d-learn
mailing list