Clean code is bullshit. Don't get me wrong: I like to have beautiful and clean code very much. But code has to be maintainable, performant, reliable, communicative, adaptive and all kind of other things before it has to be clean.
If your clean code hurts those, you made the code worse.
Sometimes you will just have to accept that things take the number of lines they do and having them duplicate in different places is a feature as you (or someone else) might have the reasonable desire to change the individual parts.
Whenever your sense of aesthetics overrides practical concerns you should pause and take a step back.
> Sometimes you will just have to accept that things take the number of lines they do and having them duplicate in different places is a feature as you (or someone else) might have the reasonable desire to change the individual parts.
The trick is always to figure out whether you are in that case or whether you are in the case where someone will want to change the shared logic everywhere at once. In my experience, the latter is vastly more common, and this is what DRY optimizes for.
That is true, but this is not case in the example.
DRY is often a good choice, but you can also use it to make logic shared that very likely never should have been shared. Untying that knot later on can become very hard compared to code where someone just had repeated themselves.
So no DRY is better than wrong DRY, but well applied DRY is of course better still (depending an what we are optimizing for).
If your clean code hurts those, you made the code worse.
Sometimes you will just have to accept that things take the number of lines they do and having them duplicate in different places is a feature as you (or someone else) might have the reasonable desire to change the individual parts.
Whenever your sense of aesthetics overrides practical concerns you should pause and take a step back.