Why do so many developers get DRY wrong?

  • Humans are good at pattern matching and developers do an even more excellent job of it. The more code you read/write, the more patterns you see coming up. And it is tempting to take those patterns, name them properly and keep referring back to them.
  • It feels really good to DRY up the code. It is really like the lowest common form of refactoring. There were days you copy-pasted code because you did not have a hang of subroutines/functions and now that you have the experience and skill to condense this code, you go ahead and do it because it suddenly feels simpler & cleaner.
  • ‘It was repetitive’ can be a trap. DRY is commonly misunderstood and leads to misguided refactoring.
  • DRY has come to mean ‘don’t cut and paste’ but the original idea behind ‘don’t repeat yourself’ had to do with knowledge, and not code. The name is itself a leaky abstraction.

Full post here, 3 mins read