In my last post I mentioned the cost of prematurely making an abstraction. To follow up on that here’s another great post on the subject. Sandi Metz is just great btw!
Duplication is far cheaper than the wrong abstraction
At the core of the talk and the post is the concept of “the sunk cost fallacy”. Developers don’t like to make new files, if it’s possible to modify something or reuse a preexisting class that’s probably what they’re going to do. So whenever you make an abstraction too early you’re leading yourself and future developers down the wrong path, because they will run with what you put in place.
Tolerate a little duplication and wait for the right abstraction.
Obviously the other side of the coin is to learn to realize when you’re decisions are being driven by the “sunk cost fallacy”.
The moral of this story? Don’t get trapped by the sunk cost fallacy. If you find yourself passing parameters and adding conditional paths through shared code, the abstraction is incorrect. It may have been right to begin with, but that day has passed. Once an abstraction is proved wrong the best strategy is to re-introduce duplication and let it show you what’s right.