Copying and Pasting is a danger to your health

All good programmers know that copying and pasting big chunks of code from one place to another instead of refactoring out into a nice reusable method is A Bad Thing. It means that any bugs which were in the original bit of code gets duplicated to the place it’s copied to. It means that when we come to modify the original piece of code, we have to modify all the duplicates too. It isn’t a pretty sight.

Still, most of us are surely guilty of doing it from time to time, and that’s where PMD comes in to help by trying to reduce smelliness in your code. I’ve only being using PMD for a single day, but its “Copy/Paste Detector” has already helped me find several big chunks of code within the web-application that I’m maintaining which have clearly been copy and pasted in haste at some previous time. Later I’m hoping to get to grips with the other features of PMD - checking for dead code, overcomplicated expressions and possible possible bugs. Should be fun!

If you enjoyed reading this and would like other people to read it as well, please add it to del.icio.us, digg or furl.

If you really enjoyed what you just read, why not buy yourself something from Amazon? You get something nice for yourself, and I get a little bit of commission to pay for servers and the like. Everyone's a winner!

comments (1) | write a comment | permalink | View blog reactions

Comments

  1. by tcopeland on December 13, 2005 08:30 PM

    Yup, the duplicate code detector is fun stuff. Did you see the duplicates it found in the Java source code?

    http:// pmd.sourceforge.net/cpdresults.txt

    Whew!

other relevant pages

about wwm

workingwith.me.uk is a resource for web developers created by Neil Crosby, a web developer who lives and works in London, England. More about the site.

Neil Crosby now blogs at The Code Train and also runs NeilCrosby.com, The Ten Word Review and Everything is Rubbish.