Comparison
Don't repeat yourselfvsIncidental duplication
Don't repeat yourself
the VAT rate changed and you had to find it in eleven places, and missed one.
Every piece of knowledge should have one authoritative representation. The original framing is about knowledge, not text: two identical-looking blocks that encode different decisions are not a violation, and two very different-looking pieces of code that encode the same rule are. Misapplied at the level of characters it produces the worst abstractions in most codebases, which is why the counter-slogans exist.
Full entry →Incidental duplication
two functions looked identical, you merged them, and a month later you added a boolean flag to tell them apart.
Code that is the same today by coincidence rather than because it expresses one rule. Merging it couples two things that were free to change independently, and the coupling is usually discovered when one of them needs to change and the other must not. The flag parameter added to a shared function is the classic tell, and the fix is to split it back apart.
Full entry →