Proposing std.typecons : Optional (with PR) + rant
Aliak
something at something.com
Tue Jun 11 21:24:47 UTC 2019
On Tuesday, 11 June 2019 at 19:02:12 UTC, Ola Fosheim Grøstad
wrote:
> On Tuesday, 11 June 2019 at 18:01:32 UTC, Nick Treleaven wrote:
>> I'd actually rather have language-assisted optional types than
>> features like function overloading (a convenience feature,
>> sometimes abused), because it means *the type system can model
>> runtime checks as a static type guarantee*. They are a game
>> changer.
>
> I don't disagree, but one often end up creating a Nobody
> subclass singleton that is used as a replacement for null.
> Although that does have benefits (e.g. if you call a
> nobody.name() you get "nobody" rather than a crash).
If there’s a possibility your class can be null then it should
probably be an optional. Or lazy. Have not seen this pattern you
describe in swift scala or Kotlin.
More information about the Digitalmars-d
mailing list