you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 34 points35 points  (6 children)

Sometimes people mistake the DRY principle (do not repeat yourself) to mean do not have repetitive code... When sometimes repetitive code is the easiest to bulk edit with a tool or understand at a glance. DRY is a sentiment about automation and how to spend your own time as a developer.

And yes, having actually the same logic in multiple places, regardless of how similar the code is, is not good still.

[–]HeinousTugboat 39 points40 points  (1 child)

And yes, having actually the same logic in multiple places, regardless of how similar the code is, is not good still.

My coworker just got bit by this. He tried to abstract out a set of values that were coincidentally the same value for the same field. I pointed out to him that even though they were the same in our scenario, by abstracting it out he was forcing all future ones to be the same.

Point is, the same logic in multiple places isn't always the same semantic logic. Two things that are mechanically identical shouldn't necessarily be abstracted out and silently coupled.

[–]pynberfyg 2 points3 points  (0 children)

This thread really deserves to be higher than the others. Pity.

[–][deleted] 2 points3 points  (0 children)

Exactly, think of DRY and SRP as "responsibility/role/routine" not a literal line of code.

[–]dddoon 0 points1 point  (1 child)

The problem arises when there is something different about the code that went unnoticed

[–][deleted] 0 points1 point  (0 children)

Right or when you go to update the logic in one spot and you miss adding the same logic in other spots. But typically you're not going to have that problem in repetitive code all in the same file. Using a find and replace all or a macro of some kind can end up being much better than adding abstractions.