DEV Community

Discussion on: Clean Code

Collapse
 
janmpeterka profile image
Jan Peterka

I slightly disagree with No duplication of code. It's a good rule on general, but sometimes its better to have duplicate code if it keeps you from bad or premature abstractions. Readability over DRYness.

Collapse
 
asafshen profile image
Asaf Shen

Well written Jan, to add few helpful quotes on top of this:

"A little copying is better than a little dependency." go-proverbs.github.io/

"duplication is far cheaper than the wrong abstraction." sandimetz.com/blog/2016/1/20/the-w...

it is common to see intermediate level developer writing complex code with high readability/maintainability cost just for the sake of DRYness

Collapse
 
tastaslim profile image
Taslim Arif

Yes Jan that's correct. Too much abstraction is also bad. Especially such abstractions which change every time you introduce new feature. At the end of day, it's you who should be aware of various scenarios while writing any abstraction. I always suggest people to write duplicate code for first and second time, for the third time if same thing arises, we can start refactoring. You can read my blog on Technical Debts and Refactoring.

Some comments have been hidden by the post's author - find out more