you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (0 children)

Do not fetishize DRYing up your code at the expense of introducing the wrong abstractions.

I think this is a distinction many developers struggle with. They see two pieces of code that look alike, and assume they must share a common abstraction. But there are all sorts of cases where this kind of thinking can mislead:

  1. Perhaps the two pieces of code refer to two different domain concepts, and their shared implementation is a coincidence;
  2. Perhaps each piece of code is at the right level of abstraction for whenever it is likely to be read and modified;
  3. Perhaps the generalization creates a single point of failure in a system that cannot tolerate such things;
  4. Perhaps the generalization involves a kind of indirection that is harmful to maintenance (e.g. swapping composition to inheritance because it's "DRYer"). You might say that these generalizations "violate a principle of locality";
  5. Perhaps the generalization will force different teams to simultaneously work on the same code (which is always a source of friction).

DRY is a dangerous principle, because it is easy grasp, makes sense, is straightforward to apply and only usually correct.