3 ms·
The problem with this is the cases when you don’t remember that you (or someone else) already used this same snippet twice. In large codebases with a lot of peo
by cimmanom 8y ago
The problem with this is the cases when you don’t remember that you (or someone else) already used this same snippet twice. In large codebases with a lot of people working on them, this can expand to dozens of copies.
- pc86 8y agoIf you have dozens of instances of nearly identical code and not a single person knows of more than 2 instances of them, you've got much bigger problems.
- kitd 8y agoThis would be true if everyone on the team was equally involved from the very start on a greenfield project, and they aren't all already fighting other forms of tech debt. Sadly the real world isn't so accommodating.
- bunderbunder 8y agoTypically, in the teams I've been on that did the best job of keeping the code clean, we'd handle this by just being good at code review: The person submitting the change might not remember any duplicates, but there's a good chance that one of the reviewers will, if that's one of the things they're watching for. Alternatively, if you really want to be exacting about this, there are code analysis tools that will do it for you.
- chooseaname 8y agoIf your code base is this big and you're adding a new feature, you really should be doing an impact analysis prior to making any changes.
- falcolas 8y agoSo, instead of dozens of copies of a snippet (which can typically be identified with tooling), the repo ends up with half as many dozens of partial abstractions? I guess it could also end up with a Frankenstein's Monster of an abstraction with more arguments and conditionals than the original code. Like walking through a doorway, descending into a function can make you lose the context surrounding that function, making it difficult to see what is actually common between the 2, 3, or 4 different invocations of that seemingly common code.
- nkingsy 8y agoCouldn’t agree more about the negative impact of this rule on a big team / large old codebase. The “copy once” rule pushes back against abstractions rather than the real problem of wrong abstractions, too big abstractions, or too complex interfaces to abstractions. We instinctually abstract by fitting n use cases into 1 abstraction, when in fact we should be inverting the dependency graph and writing or reusing n abstractions for each use case.
- zeveb 8y agoI think that's okay, because those large, multi-person codebases are precisely the ones which pay a huge cost for premature abstraction. Too much copy-pasta is a great reason to refactor.
- rakoo 8y agoThat's why you have your code reviewed by other people in the team before it hits master.
- lackbeard 8y agoOr worse, you need to change some behavior and it it only gets changed in one of those places...