invert sense of ? with compound assignment #969
However, prior to this commit, the code
Contrast with accessignment, where
This commit makes
Technically a breaking change, but I don't see how the feature would have been put to any good use before, so I'm treating this as a minor bug fix and waiting one week before merging on June 26, unless, as always, there are objections.
The code `a ?= b` is basically `a? || a = b`, which is all well and good; it makes sense to want to assign to `a` if it's nullish. However, prior to this commit, the code `a ?+= b` was basically `a? || a += b`, which is useless. If `a` is nullish, I certainly don't want to add anything to it. Contrast with accessignment, where `a?=b` is basically `a? && a.=b`. Obviously better this way. This commit makes `a ?_= b` mean `a? && a _= b`, as with accessignment, for any compound assignment operator. (`a ?= b` and `a ?:= b` are unchanged.)
actor.health ?+= 10
increments actor’s health if it exists (even if it's 0), whereas
actor.health &&+= 10
only does so if actor has a nonzero health.
I feel like there are at least as many, if not more, use cases for the former as for the latter.
Again, I'm shooting for consistency with what accessignment does: compare
That seems like a completely independent question—or am I missing your point? Even with the explicit dot,