4 ms·
When in doubt, I use this rule of thumb: - It is ok to have the code duplicate twice. Add a comment to track the conscious decision. - But when I find myself
by ChrisCinelli 8y ago
When in doubt, I use this rule of thumb:
- It is ok to have the code duplicate twice. Add a comment to track the conscious decision.
- But when I find myself to do it the 3rd time, it is time to think if I can factor it out.
Three use cases tell me more than two about how things can be abstracted and if it makes sense.
- kungtotte 8y agoI think the wording of the second part is crucial. Thinking if you can factor it out is a way different beast than "you must refactor to obey DRY". Implied in your statement is whether or not the abstraction can be made simply, efficiently, cleanly, etc. which all serve to make it a good abstraction. If your only priority is removing duplication at all costs, you'll end up with worse code than if you just let code be duplicated.
- abakus 8y agoBut the whole point of this discussion is that you should probably duplicate as many times as needed if it helps to avoid wrong abstraction.
- PDoyle 8y agoNo. The point of the article is that it's ok to undo an abstraction that has done more harm than good. Abstraction and DRY is still a good default mode of thinking.