𝗖𝗼𝗱𝗲 𝗗𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝘃𝘀. 𝗪𝗿𝗼𝗻𝗴 𝗔𝗯𝘀𝘁𝗿𝗮𝗰𝘁𝗶𝗼𝗻𝘀

Developers often struggle with a choice.

You must choose between the Don't Repeat Yourself principle or allowing some code duplication.

DRY is a core rule in software design. But chasing it too hard creates a new problem. You create a wrong abstraction.

A wrong abstraction costs more than duplicate code.

We want to write elegant code. We want to build reusable logic. We want to fix a bug in one place and see it fixed everywhere. This goal feels right.

But premature abstraction kills project speed. It ruins how easy it is to maintain your code.

When you abstract too early, you face these issues:

  • Increased complexity. Bad abstractions add layers of confusion.
  • Rigid code. It becomes hard to change one part without breaking others.
  • Hidden logic. You spend more time tracing code than writing it.

Sometimes, duplication is the pragmatic choice. It keeps your code simple and clear. It allows you to change parts of your system independently.

Do not build a generic solution for a problem you do not fully understand yet. Wait until the pattern is clear.

Source: https://dev.to/kelvin_kariuki_20f4bec616/developer-take-on-code-duplication-is-far-cheaper-than-the-wrong-abstraction-2016-2k3n