there are several reasonsbut they all boil down to readability and maintainability when we're writing new piece of code that is similar to an earlier piecethe easiest thing to do is copy the old code and change whatever needs to be changed (variable nameslogiccommentsto make it work in the new location alternativelyif we're writing new code that seems similarbut not identical to code elsewhere in the projectit is often easier to write fresh code with similar behaviorrather than figure out how to extract the overlapping functionality but as soon as someone has to read and understand the code and they come across duplicate blocksthey are faced with dilemma code that might have made sense suddenly has to be understood how is one section different from the otherhow are they the sameunder what conditions is one section calledwhen do we call the otheryou might argue that you're the only one reading your codebut if you don' touch that code for eight months it will be as incomprehensible to you as it is to fresh coder when we're trying to read two similar pieces of codewe have to understand why they're differentas well as how they're different this wastes the reader' timecode should always be written to be readable first once had to try to understand someone' code that had three identical copies of the same lines of very poorly written code had been working with the code for month before finally comprehended that the three "identicalversions were actually performing slightly different tax calculations some of the subtle differences were intentionalbut there were also obvious areas where someone had updated calculation in one function without updating the other two the number of subtleincomprehensible bugs in the code could not be counted eventually replaced all lines with an easy-to-read function of lines or so reading such duplicate code can be tiresomebut code maintenance is even more tormenting as the preceding story suggestskeeping two similar pieces of code up to date can be nightmare we have to remember to update both sections whenever we update one of themand we have to remember how the multiple sections differ so we can modify our changes when we are editing each of them if we forget to update both sectionswe will end up with extremely annoying bugs that usually manifest themselves as"but fixed that alreadywhy is it still happening?the result is that people who are reading or maintaining our code have to spend astronomical amounts of time understanding and testing it compared to if we had written the code in nonrepetitive manner in the first place it' even more frustrating when we are the ones doing the maintenancewe find ourselves saying"why didn' do this right the first time?the time we save by copy-pasting existing code is lost the very first time we have to maintain it code is both read and modified many more times and much more often than it is written comprehensible code should always be paramount