Skip to content

Files

Latest commit

 

History

History
23 lines (17 loc) · 486 Bytes

misrefactored-assign-op.md

File metadata and controls

23 lines (17 loc) · 486 Bytes

Pattern: Redundant assignment operation

Issue: -

Description

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.

Examples

Example of incorrect code:

x += x + y;
count -= count - total;
sum *= sum * factor;

Example of correct code:

x += y;
count -= total;
sum *= factor;