Current sentiment on Nullable.get
Steven Schveighoffer
schveiguy at gmail.com
Mon Dec 10 16:02:32 UTC 2018
On 12/10/18 5:01 AM, 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.
Wow, I didn't realize that get, in production with asserts off, is no
different than just any T. It's practically useless.
I don't think we can simply deprecate that feature. All you will see is
people adding "get" to all the accesses, but still resulting in the same
problem.
I was going to suggest changing the assert to an enforce, but that
changes the nothrow semantics.
I think we'd be better off adding a new type, which does what people
want, and deprecating Nullable completely.
-Steve
More information about the Digitalmars-d
mailing list