I like this part: “Duplication is sometimes essential for the right abstraction. Because only when we see many parts of the system share “similar” code, a better shared abstraction emerges. The Quality of Abstraction is in the weakest link. Duplication exposes many use cases and makes boundaries clearer.”
I just did this yesterday... copy/pasted some code from one function to another function, tested that the new function works and moved on, and then when I went back to work more on it, I wrote more generic code that can be called by either function. Don't have to overthink things before writing the first function.
I tend to see this when people try to pre-emptively abstract. Not "we seem to be duplicating 3+ blocks of code here" but "we might want to do this again at some point so we need an abstraction to make it easier next time".
The former almost always works while the latter almost always fails.
The former gives a little dopamine hit and a boost to the ego because that's being "an architect" while the latter feels more like being a janitor. Ironic really.
Interestingly, the second approach is often recommended in functional languages, although in a slightly different way; compose complex/complicated logic of small pieces. You end up with a lot more functions but it allows for code reuse.
I am note quite sure, though, if we can already talk about an abstraction then.
There is no code reuse of small non-generic functions in practice, just duplication and thus ravioli code. And to make these small functions generic costs time.
What may make sense is to make something similar to lemma in proofs. This is strictly for ease of debugging or readability.
I think "kill your ego" and be happy with the janitorial aspect of it.
De-duplication is "equivalent" to ( LZW style ) compression, and LZW compression is a solved problem. But local conditions may insist more on de-duplication.
I just did this yesterday... copy/pasted some code from one function to another function, tested that the new function works and moved on, and then when I went back to work more on it, I wrote more generic code that can be called by either function. Don't have to overthink things before writing the first function.