4

Programming insight #4
Even if code is repeating just twice it's still better to add it in a function/submodule and call the function/submodule twice.
In future, if a bug comes in that section it's quicker to fix it at one place than at two different ones thereby reducing the cases of missing unhandled bugs.
TLDR: The lesser the code is repeated the lesser are future bugs in code

Comments
  • 3
    Only if it's actual duplication. If it's coincidental duplication (moment of simultaneous invention), then you're just buying yourself tech debt because it's not actually the same code.

    Tl;dr If the implementations need to diverge due to its involvement in an algorithm that doesn't have compatible genericism, you've now done the work 3 times instead of twice.
  • 1
    Yes, but if there's only a bug in one or the other time it's run but not both you're fucked.
Add Comment