Don't Repeat Yourself

2012 11 13

Don’t repeat yourself. But, all things in moderation; counterpoint:

Sometimes repeating code is simpler and easier to understand than trying to force an abstraction just to avoid duplication. I think code readability and ease of understanding trumps other concerns. I would rather have a function I can read top to bottom and understand what is happening than to avoid duplication just for the sake of DRY. I think Go hits the sweet spot in this regard. I’ve had nightmares debugging in dynamic languages where DRY is taken to the extreme and you are lost in a maze of indirection because the library authors wanted to avoid repeating a couple lines of code here and there.