Cut and paste reuse is simple and easy – so why pursue systematic reuse? For all the seeming benefits it has significant disadvantages. For instance:
- It increases codebase size. There is nothing eliminating duplication – so the codebase starts to contain multiple instances of similar logic. Systematic reuse aims to cut down the amount of incremental code that needs to be written to address new requirements.
- Lose the benefits of enhancements and bugfixes: everytime you “fix” a problem with cut and paste code – that has to be propagated across the codebase. This isn’t trivial – every where the cut and paste code was originally placed, would now be coupled with various other classes.
- Doesn’t promote consistency in behavior – cut and paste from one part of the codebase to another might save time in the short term but will quickly lead to different behaviors for achieving a capability. Over time, this increases the size and complexity of your solutions.
- Makes it hard to refactor – related to the earlier point – when you refactor, there is extra care needed to make sure that new defects aren’t introduced and existing code is identified carefully. That being said, refactoring will help you reduce the amount of duplicate code and move towards a more reusable, more modular design.