
The Fallacy of Code Reusability
How the dogmatic pursuit of DRY (Don't Repeat Yourself) creates premature abstraction and legacy nightmares.
The DRY Religion
"Don't Repeat Yourself" (DRY) is one of the first principles taught to junior developers.
It makes intuitive sense: if you have the same logic in three places, you should extract it into a single, shared function. This reduces lines of code and ensures that if the logic changes, you only have to update it in one place.
But like any religion, when DRY is applied dogmatically, it destroys the system it was meant to save.
"Premature abstraction is the root of all legacy code."
The Cost of Coupling
When you extract code into a shared, reusable component, you are creating a dependency. The three separate places that used to operate independently are now permanently coupled to the shared component.
In month one, this is fine because the three places all require the exact same behavior.
In month six, the product manager requests that Place A behave slightly differently. Because Place A uses the shared component, the engineer adds a boolean flag (isPlaceA) to the component to handle the edge case.
In month twelve, Place B needs a different behavior. Now the shared component has five configuration flags, a massive switch statement, and is utterly incomprehensible. Modifying it for Place C now risks breaking Place A and Place B.
WET Code: Write Everything Twice
The alternative to DRY is WET: Write Everything Twice (or, We Enjoy Typing).
Before you extract code into a reusable abstraction, you must let the duplication exist long enough to understand its true nature. Code that looks identical today may evolve in completely different directions tomorrow. If you abstract it too early, you bind those two distinct evolutionary paths together artificially.
The Rule of Three: Do not create a reusable abstraction until you have written the exact same code three times.
Duplication is vastly cheaper than the wrong abstraction. A duplicated function can be modified safely in isolation. A highly coupled, heavily abstracted "reusable" component is a landmine waiting to detonate your engineering velocity.

Kai Cyrus
Founder, Builder, Investor