Maintaining code over long periods of time is much easier when we only need to change the code in one place, and when we can recombine existing pieces of code. One of the most effective ways to move toward this ideal is to identify and to remove duplication from code. The operations from functional programming—partial application, currying, and functional composition—offer many opportunities to make code cleaner and with limited duplication.
But first, let's understand what duplication is and why we need to reduce it. First, we'll look at the Don't Repeat Yourself (DRY) principle, and then at the relationship between duplication and code similarity. Finally, we'll look at ways to remove code similarity.