Quote (tt_toby @ Sep 2 2013 04:21pm)
You did not say which version is more readable to you, though. Opinions on this might actually differ.
cannot give an answer because it depends on the meaning of the variables. you're forgetting a lot more options
1) a -= b - c
2) a = a - b + c
3) a -= (b - c)
4) a = a - (b - c)
5) a = a - b - (-c)
6) a -= b; a += c;
or how about remove the compound operator entirely and use another variable
total = b - c
total = -(b + c)
suppose you are calculating the sum vector formed by two vectors, one pointing up and one pointing down.
vector = up - down
now suppose you have a parameter that will reduce down by some amount delta. then this makes perfect sense
vector = up - (down - delta)
whereas this may be a little confusing:
vector = up - down + delta
now suppose you have a parameter that will increase up by some amount delta. this this makes perfect sense
vector = (up + delta) - down
whereas this will be confusing
vector = up - (down - delta)
tldr if the business logic says (b - c) should be removed from a, then a -= (b-c) is fine. whereas if the business logic says c should be added, then don't put a negative sign.
This post was edited by carteblanche on Sep 2 2013 02:43pm