Comment on Opinions on how to deal with duplicate code.
robinm@programming.dev 1 year ago
There are 2 metrics that need to be considered:
- easy to read
- easy to modify
The first point is by far the most important. Usually DRY win because less code means less to read so less to put in your head. But if the abstraction is too complicated (for example because there are two many parameteres) then it’s worth considering drying.
And don’t forget the second point, but do not overthing and YAGNI. Sometime a simple comment “don’t forget to update method foobar()
” is enough. Don’t forget either that you can always rewrite the abstraction when you need to modify something (if the original did not fit your new requirements), but for this to be an easy task, the understanding of the original abstraction must be crystal clear. That’s why the first point is so important.