4 ms·
Code duplication reduces coupling between multiple unrelated pieces of code. Edit: not sure why the downvotes, perhaps these people have never seen a junior en
by xwdv 7y ago
Code duplication reduces coupling between multiple unrelated pieces of code.
Edit: not sure why the downvotes, perhaps these people have never seen a junior engineer go on a fanatical deduplication spree across a whole project, or perhaps these are the junior engineers.
- YesThatTom2 7y agoA little code duplication prevents mounds of dependencies. I’ve seen people link to multi-megabyte modules to save one line of duplicated code. At Google this was a disease. Good to see they’re fixing it.
- manaskarekar 7y agoSurely there is a middle ground.
- xwdv 7y agoYes, the middle ground is to avoid duplication when code is non-trivial. Most code is trivial.
- fauigerzigerk 7y agoI think there's more to it than finding the middle ground. The question we should ask is whether or A should change whenever B changes. If the answer is yes then there should be a dependency. If the answer is no then no dependency should exist, even if some lines of code happen to be identical at a particular point in time. (That's probably what you alluded to when you said "unrelated pieces of code" and I agree with that). The number of lines of code shouldn't be the primary concern though. For instance, if some tax is calculated in a particular way as a matter of law, then that calculation should exist exactly once in the entire code base, even if it's just one line of code.
- house9-2 7y ago"Don't make the code so DRY it chafes"
- sagichmal 7y agoIn Go, the informal rule is to duplicate the second time you need a bit of code, and factor out only on the third time.
- sidlls 7y agoIt's not just junior engineers. Senior engineers do this, too: fanaticism and adherence to some set of practices no matter what, regardless of the context are as much a bane in this industry as chasing the latest shiny is.