4 ms·
This "rule of three" seems to be fashionable these days, but I think you'd want "the rule of 2" all the way to "the rule of 10" depending on the size of the dup
by Aardappel 8y ago
This "rule of three" seems to be fashionable these days, but I think you'd want "the rule of 2" all the way to "the rule of 10" depending on the size of the duplicated code, how hard it is to abstract, the complexity of the resulting abstraction, the distance between uses and abstraction, etc.
I certainly wouldn't want to wait to 3 if I am copying a block of 10+ lines that requires just a single int parameter to abstract into a function very local to the 2 uses. And I may use "the rule of never" on a 2 liner that requires a callback to abstract.
- brianpan 8y agoIt's a rule of thumb. You don't refactor if and only if three duplicates exist.