Current sentiment on Nullable.get

aliak something at something.com
Mon Dec 10 15:47:53 UTC 2018


On Monday, 10 December 2018 at 10:01:45 UTC, FeepingCreature 
wrote:
> Having recently been reminded that `alias Nullable.get this` 
> exists, I'm considering a pull request to deprecate it. What's 
> the sentiment on `alias Nullable.get this` in the community? My 
> unchanged stance is that it's a blight and an interminable 
> source of impossible to find runtime bugs, and an anti-feature 
> that misses the point of Nullable to provide safe optional 
> types.
>
> The typical problem goes like this:
>
> 1. A dependency switches from T to Nullable!T.
> 2. You update your dependencies.
> 3. Your program still compiles (because Nullable!T silently 
> casts to "T or exception") and you notice nothing.
> 4. Sometime later, your program crashes in production.
>
> Thoughts?

Sounds like a step forward, deprecating that.

Do people consider Nullable a type of Optional thing in general? 
I have a written a bit more details here [0] but basically I 
don't think deprecating .get is enough to make it "safe" - 
granted - depending on what safe means. In the context of D a 
segfault is safe so maybe that's ok. But then deprecating get 
doesn't add safety in that context anyway. And, I've never really 
considered Nullable as something that provides Optional 
semantics. But maybe that was it's intention?

[0] 
https://github.com/aliak00/optional/blob/03e0dc0594f1f19274389227e67dd3fba00a9d3f/README.md#what-about-stdtypeconsnullable-and-stdrangeonly


More information about the Digitalmars-d mailing list