Coding Practice: Analyzing Code Clones

Coding Practice: Why doesn’t someone make a tool to help you detect code duplication and opportunities for refactoring?
Someone does.  In fact, it is built into Visual Studio 2012 (Ultimate and Premium editions) under the Analyze menu > Analyze Solution for Code Clones.  Running this tool will search through your solution for duplicate code and is capable of finding “near miss” clones.

“Duplication may be the root of all evil in software.  Many software practices have been created for the purpose of controlling or eliminating it.”
–            Robert Martin

Consider running code clone analysis whenever you write new code just to check to see if similar code already exists.  You will definitely want to run code clone analysis as part of your code review process just to make sure you aren’t missing an opportunity to refactor your code in observance of the DRY (Don’t Repeat Yourself) principle.I already touched this topic earlier when discussing “when is it okay to cut and paste code”, but I thought this tool was significant enough to warrant an extra post just to draw attention to it.


About Chris VanHoose

Principal Software Architect at CT Lien Solutions
This entry was posted in Software Architecture and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.