Pattern: Redundant assignment operation
Issue: -
Using patterns like a += a + b
or a -= a - b
is likely a mistake. These expressions can be simplified to a += b
or a -= b
respectively, as the original variable is being added or subtracted unnecessarily.
Example of incorrect code:
x += x + y;
count -= count - total;
sum *= sum * factor;
Example of correct code:
x += y;
count -= total;
sum *= factor;