4 ms·
If code block A has X bugs and code block B=A. Then a code block containing B+A still contains X bugs.
by laythea 9y ago
If code block A has X bugs and code block B=A. Then a code block containing B+A still contains X bugs.
- AnimalMuppet 9y agoBut if I fix all X bugs in code block A, then a code block containing B+A still contains X bugs. That's one of the big problems with code duplication. "You fixed a bug? Great. Did you fix it everywhere?" It's better if there's only one place to fix it, because when you've fixed it, you've fixed all of it. But as others have said, eliminating this is not the only good thing in programming. There are limits to how far you should go to prevent or eliminate duplication.
- naasking 9y ago> It's better if there's only one place to fix it, because when you've fixed it, you've fixed all of it. You've got one aspect, and the other aspect is that code factored into a reused function F is now reviewed more too, ie. whenever you're reviewing the callers, you work through the functions they call as well to trace the behaviour. So you're also much more likely to find any bugs in F. It's a double-whammy for bug squashing, which is why DRY is such an important principle. Certainly there are some misapplications, but its benefits hold up pretty well in a wide variety of scenarios.
- whathaschanged 9y agoIf the bug being fixed was expected behavior by all the other dependencies, you just screwed over everyone else who should have duplicated what they needed in the first place.