4 ms·
Glad it's not just me. While in general the advice on duplication is reasonable I think it tends to get taken too far and the example is a poor one. Presumabl
by UglyToad 7y ago
Glad it's not just me.
While in general the advice on duplication is reasonable I think it tends to get taken too far and the example is a poor one.
Presumably for now Mexico applies a different sales tax % but there are so many unknowns on how Mexican tax rates differ that I'd keep the method separate until I'm certain the abstractions are similar, otherwise you might end up with:
calculateBill(locale, appliesExemption, exemptionRate, regionalTaxRate, nationalTaxRate, clothing Untaxed)
Premature abstractions seem worse to me than some duplication.
Besides something like bill calculation should have loads of tests.
- rightbyte 7y agoTrue story. Dogmatism is really bad always. If copy pasting into 10 almost identical functions seems resonable just do it. Atleast it obvoius that the code is a mess and that is not hidden in deep abstractions.
- ehnto 7y agoSometimes the requirements just demand lots of arbitrary but similar code, and chasing elegant abstractions is a waste of time and less robust than the nearly duplicate code blob.
- wool_gather 7y agoAgree, but please leave a comment to that effect so that I don't come into the codebase long after you've left and waste the same amount of time refactoring only to reach the same conclusion! :)