BranchDuplicate
Detector that reports duplicated code in conditional branches.
Why is it bad?
Duplicated code in branches is bad because it:
- Reduces Readability: Repetition makes the code harder to understand.
- Increases Maintenance: Changes must be made in multiple places, risking errors.
- Signals Poor Design: It suggests missed opportunities for cleaner, more abstract code.
Example
if (a > 42) {
a = 43; // bad: duplicated code
} else {
a = 43;
}
Use instead:
if (a > 42) {
a = inc(b); // ok
} else {
a = 43;
}