We'll now cover the DRY principle:
- D: Don't
- R: Repeat
- Y: Yourself
This acronym is a good way of reminding programmers that duplicate code is bad. It is obvious that duplicate code can be difficult to maintain—whenever logic is changed, multiple places in the code are affected.
What do we do when duplicate code is found? Eliminate it and create a common function that is reusable from multiple source files.
In addition, sometimes code is not 100% duplicated but instead is 90% similar. That is not an uncommon scenario. In that case, consider redesigning the relevant components, possibly refactoring code to a common interface.