DEV Community

Discussion on: Stop trying to be so DRY, instead Write Everything Twice (WET)

Collapse
 
wuz profile image
Conlin Durbin

Anyone who thinks that maintaining even two copies of a piece of code is easier than one subroutine or function should not be allowed in a team.

Sorry you feel that way Denis! In my experience, the best teams are those that have constructive conversations around these kinds of concerns! I definitely wouldn't want to have to work on that much duplicated SQL, but I still believe there is only so much usefulness to be gained from abstraction. This sounds like a situation where the code would have benefited from abstraction after the 3 time it was duplicated.

When would you draw the line around abstraction? Would it be after just the second time you had to write it?

Collapse
 
denishowe profile image
Denis Howe

Sorry, I explained badly. The original code was duplicated so there were two copies of it, then those two were duplicated so there were four copies, and so on, doubling each time. (There were some minor differences between copies that were easy to parametrise).

The point is that each copy and paste was a crime in itself, even the first one that only created two copies of a fairly short bit of code.

Saying to yourself, "I'll abstract that later if I need to" is just not good enough as it risks the copies diverging in ways they shouldn't and leaves it up to the next guy to find, understand and fix your mistake or to perpetuate it by applying the same fix in multiple places. Experienced programmers avoid duplication because it makes maintenance harder.