DRY Principle Debate

Comments debate the trade-offs of the DRY (Don't Repeat Yourself) principle versus accepting code duplication to avoid premature or poor abstractions that reduce readability and maintainability.

📉 Falling 0.3x Programming Languages
3,823
Comments
20
Years Active
5
Top Authors
#8263
Topic ID

Activity Over Time

2007
11
2008
15
2009
53
2010
54
2011
69
2012
77
2013
109
2014
112
2015
112
2016
293
2017
201
2018
146
2019
226
2020
502
2021
326
2022
392
2023
493
2024
383
2025
239
2026
10

Keywords

OO IMO HN OP DDRY OK IME AND DRY code duplication abstraction dry duplicated abstractions repeat change codebase premature

Sample Comments

mimog May 18, 2015 View on HN

You are violating DRY principle. Copied code, with minor variation, spread out through a codebase is, seriously, the root of all evil.

kevinqi Aug 5, 2025 View on HN

duplicate code is not that bad. reduce duplication over time as you find the common patterns/abstractions, instead of trying to build abstractions too early

dgan Sep 13, 2024 View on HN

Can you expand om what of code duplication you deem reasonable?

ryeats Aug 31, 2025 View on HN

This is a trap junior devs fall into DRY isn't free it can be premature optimization since in order to avoid copying code you often add both an abstraction AND couple components together that are logically separate. The issues are at some point they may have slightly different requirements and if done repeatedly you can get to a point that you have all these small layers of abstraction that are cross cutting concerns and making changes have a bigger blast radius than you can intuit easily.

jonno123 Dec 19, 2020 View on HN

Couldn’t agree more. I can agree that premature abstraction is bad. But unnecessarily duplicated code outweighs this by orders of magnitude, in my experience. So stay DRY, and later when you hit that 1 case in 100 where the code needs to diverge, it’s easy enough to copy/paste.

mooktakim Jul 7, 2022 View on HN

New devs start with doing DRY everywhere. Over time they learn to be more thoughtful. Sometimes duplication is good. In my experience the priority should always be dev readability. If duplication helps you read the code better (as its not hidden away), thats fine.

z3t4 Apr 14, 2017 View on HN

It's easy to duplicate code. But hard to delete shared code.

jimjimjim Sep 18, 2016 View on HN

The idea of 'don't repeat yourself' is an ok guideline unless, like most proverbs/sayings/mottos/slogans it gets used as a absolute rule.feel free to ignore it, mock it and toss it aside if it leads to bad abstractions, highly convoluted structures or write-only code.anyone that has had to do maintenance or adding features to a large OO codebase from the early 2000s will have seen vastly massive class hierarchies where following the path of execution is a roll

taurath Aug 15, 2019 View on HN

Duplication is always more extensible and maintainable than a bad abstraction.

oxalo Apr 25, 2014 View on HN

Sort of falls under the DRY (Don't Repeat Yourself) principle.