Duplication Over Abstraction

It’s better to favor duplication over the wrong abstraction. The wrong abstraction starts out as a way to remove duplication and then gets altered over time to handle more and more conditions to the point where it’s unique to all the callers.

When this happens, the best solution is to ‘go backwards’ and inline the relevant code to the callers (with their respective special cases).

Read The Wrong Abstraction by Sandi Metz.

See also:

  • Optimize for Reducing State, Coupling, Complexity, and Code

    To optimize code, reduce state, coupling, complexity, and code, in that order. Reducing state makes the program easier to reason about (e.g. pure functions are easy to test). Be willing to add more coupling if that means less state, more complex if it decreases coupling, and duplication if it makes code less complex.