.NET Zone is brought to you in partnership with:

I’ve been a Windows developer since 3.0 and caught the Visual Basic wave early with v1. I’ve released a “production” application in every version of VB since then (except VB for DOS). Focusing on enterprise, line-of-business development I’ve built Call Center Applications, Mortgage finance systems, Customer Relationship Management tools and more recently I’ve been in the Litigation Support/Electronic Data Discovery/Electronically Stored Information space. Greg is a DZone MVB and is not an employee of DZone and has posted 482 posts at DZone. You can read more from them at their website. View Full User Profile

CTRL-V Code Much? Here's a Visual Studio Feature to Help You

  • submit to reddit

JasonSingh - Problems with Copy Pasting Code - And Modifying Slightly... Then How To Go Back And Fix It All Up Afterwards.

As developers, we often find ourselves under a lot of pressure to crank out code and copy then paste it somewhere else in a solution and make a slight modification here and there and get the product out the door. It's a frequent occurrence and hence the number of lines of code is not a great measure of quality code. There's nothing wrong if it gets the code out the door, however, when we have time we can go back and fix this.

What happens, if we don't and some code has been copied and pasted in different renditions and a bug comes up in one of the scenarios? We can fix it in the one instance, but that bug may also be applicable in all or some the copy/paste instances of code.

Considering the frequency of these scenarios, we've introduced Code Clone Analysis in Visual Studio 2012. What is does it search a solution and looks for similar code.

From the Analyze menu in Visual Studio 2012, we select "Analyze Solution for Code Clones"


So, when you get a chance, like a couple of minutes, check out the tool and see how much copying and pasting has been going on in your team ;)

Speaking of CTRL-V love, I thought this post a great kind of counter-point to my last post, If CTRL-V is your coding friend (admitted or not), Check out Paste FixR.

So maybe feel you do paste in a little much? Or that maybe a team member does? Or you both do? This Visual Studio feature will help you find and fix those [code] clones.

Related Past Post XRef: 
If CTRL-V is your coding friend (admitted or not), Check out Paste FixR

Published at DZone with permission of Greg Duncan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)