3 ms·
IME abstractions generally begin with the latter case. Perhaps there's one or two corner cases that the abstraction also covers, but it seems justifiable at the
by whakim 5y ago
IME abstractions generally begin with the latter case. Perhaps there's one or two corner cases that the abstraction also covers, but it seems justifiable at the time because the core of the code really ought to work the same across all cases. Then you slowly start adding corner cases, or you change your new feature slightly so that the abstraction has to change. Little by little you end up with this insanely complicated (and unclean) abstraction which is arguably significantly worse than simply duplicating the code would have been in the first place. I make this remark because I think that "the code needs to be the same in a few places" may not be a sufficiently strong reason for writing an abstraction right away. Even in these cases, sometimes it's ok to leave duplication in your codebase for a little while while you let the feature you're working on shake itself out, then come back and see if the abstraction is worth writing. That's the only way to break the cycle.
- makeitdouble 5y agoAn issue in the duplicated approach is keeping track of the different blocks once they diverge enough. In the best case scenario they all slighty change over time without forcing complexity on each other. But it becomes a problem as changes that should be breaking only break part of the code, and the rest can go unfixed as nobody remembers all the linked bits. It would be critical for instance if the duplicated bits were involved in invoicing procedures, and one in five remained unchanged while the other got updated.
- whakim 5y agoI'm not necessarily claiming that all abstractions are bad. I'm say that (as a general rule) engineers should be more willing to duplicate code.