DRY is not about *code duplication*
Code Example
“Never allow similar code to exist.”
That’s not DRY.
The original idea behind DRY wasn’t “remove every repeated line.”
It was:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
— Andrew Hunt and David Thomas (The Pragmatic Programmer)
Knowledge duplication.
Not code duplication.
Want releases to stop feeling stressful and unpredictable?
I’m running a live CI/CD Pipeline Workshop where we build systems that catch issues before production — not after deployment panic.
€100 off with code EARLYBIRD100 — limited spots.
❌ Two identical lines are not always duplication
Developers see this:
public class InvoiceTaxCalculator {
public BigDecimal calculateTax(BigDecimal subtotal) {
return subtotal.multiply(new BigDecimal("0.20"));
}
}…and then later see this:
public class ImportDutyCalculator {
public BigDecimal calculateDuty(BigDecimal subtotal) {
return subtotal.multiply(new BigDecimal("0.20"));
}
}The callers would call:
var tax = invoiceTaxCalculator.calculateTax(subtotal);
var duty = importDutyCalculator.calculateDuty(subtotal);And immediately someone says:
“We should extract this into a shared utility.”
So it gets merged.
So we decide to get rid of the duplication, by extracting duplicated code here:
public class Calculator {
public BigDecimal calculate(BigDecimal subtotal) {
return subtotal.multiply(new BigDecimal(”0.20”));
}
}We then realize we don’t need neither InvoiceTaxCalculator nor ImportDutyCalculator, so we delete them too.
Then, the callers would call:
var tax = calculator.calculate(subtotal);
var duty = calculator.calculate(subtotal);But the problem is that Invoice Tax and Import Duty calculations are completely unrelated from the business perspective. They have completely different business rules.
Today, they happen to have the same formula, but that is just incidental.
Tomorrow, they will end up with different business rules:
public class InvoiceTaxCalculator {
public BigDecimal calculateTax(BigDecimal subtotal, String category) {
if (category.equals("FOOD")) return subtotal.multiply(new BigDecimal("0.05"));
if (category.equals("ELECTRONICS")) return subtotal.multiply(new BigDecimal("0.18"));
return subtotal.multiply(new BigDecimal("0.20"));
}
}
public class ImportDutyCalculator {
public BigDecimal calculateDuty(BigDecimal subtotal, String country) {
if (country.equals("US")) return subtotal.multiply(new BigDecimal("0.25"));
return subtotal.multiply(new BigDecimal("0.30"));
}
}Now the shared abstraction becomes a bug factory.
flags everywhere
branching logic explosion
“generic” calculator that no longer represents a real concept
The duplication was never the code.
The real mistake was coupling two unrelated business concepts because they happened to look similar at one moment in time.

