7 ms·
> If you want to make sure the value doesn't disappear, you shouldn't be using conditional assignment in the first place. If it worked using "materialize-on-wr
by kazinator 1y ago
> If you want to make sure the value doesn't disappear, you shouldn't be using conditional assignment in the first place.
If it worked using "materialize-on-write" semantics, why wouldn't you, as an alternative to the verbose code which checks every path component that might not exist, and instantiates it before doing the assignment?
Obviously, you can't use it if you don't have materialize-on-write semantics in the assigned expression not that you shouldn't.
- Dylan16807 1y agoIf it materialized instead, yeah that sentence wouldn't apply the same way. But materializing with a default constructor opens up many cans of worms. I would say it has significantly more downsides than short circuiting. Also it should use a different operator.
- kazinator 1y agoSmall additional point: if it used a different operator, what if that operator was used in an expression that is not the target of an assignment? Does that operator just become equivalent to ?, or does it do the materializing anyway even though it is not required in support of an assignment?
- Dylan16807 1y agoIt would probably materialize no matter what. But syntax error would be fine. Definitely not acting the same as a question mark.