3 ms·
I can't agree or disagree unless I know: - duplication of what, and how many times? Three times? Five? Forty-seven? Four hundred? One line, Five lines, or fift
by kazinator 3y ago
I can't agree or disagree unless I know:
- duplication of what, and how many times? Three times? Five? Forty-seven? Four hundred? One line, Five lines, or fifty?
- does the abstraction completely de-duplicate? Or does it turn N big duplications into one some big common code and N much smaller duplications?
You should almost never duplicate more than two, at most three times. Or, should I say, never have to duplicate. If duplication is the best solution, because there isn't a suitable abstraction or we can't find it, there should be a macro system which can condense the duplication. So that is to say, if you have maros, there is always an abstraction that can be found, namely syntactic abstraction. Identify what is common between the duplications, and turn that into template. The variant parts become parameters.
If that turns out later to be worse than duplication, you can just expand it and keep the expansions or identify some other way to deduplicate them.