DRY can be expensive

Don't repeat yourself! Except when doing so might be harmful...

If I’ve told you once, I’ve told you a thousand times: I never repeat myself.

And neither should you! Right? Don’t repeat yourself, or the DRY principle tells us this.

There are many ways to apply the DRY principle in IT systems. In code, it can be as simple as extracting a common behavior into a function that can be called from multiple places.

But when can DRY be harmful? Here are a few cases…

  1. It breaks the flow of the code
  2. It adds new dependencies to manage
  3. Too many abstractions can be hard to follow
  4. The wrong abstraction is used (often caused by premature optimization)
Share this