Action Show solution with 2 files open in side by side mode in the editor. As the dialog progresses draw a highlight box ...

Action
Show solution with 2 files open in side by side mode in the editor. As the dialog progresses draw a highlight box in both files around the code fragments that "match". (Note: The matched code fragments should not be textually identical, but fragments that will be detected by code clone analysis)

Dialogue
As a code base grows and evolves, it's inevitable that duplicates arise in the code. Developers invent the same solutions many times. Duplicates make life difficult by increasing the cost of maintenance for code. It is difficult to make changes and fixes to a fragment and discover and propagate those changes to other fragments. 

With Visual Studio, you can use the code clone feature to find clones of specific fragments or all clones in a solution. Visual Studio will display similar fragments side by side. You can decide whether to refactor them into a single function or to leave them unchanged.



Action
Highlight a fragment of code. Right click on it -> Find Matching Clones in Solution. Expand results window to show some found matches.

Dialogue
Code clone detection is really easy to use; it is only a single click. Highlight a fragment of code you may think has duplicates. In the right click context menu select Find matching clones in solution. Matches will be shown in the Code Clones Results window.



Action
Select from menu Analyze -> Analyze Solution for Code Clones. Show the code clone matches in the results window. Expand a few to show the matches.

Dialogue
In addition to searching for a specific fragment the Code Clone tool can also find all clones in your solution. Select Analyze menu then Analyze Solution for Code Clones. All code clones in your solution of greater than 10 lines will be return. 



Action
A results window with code clones shown. Select 2 code clones. Right click, select Compare. Show the diff window.

Dialogue
A side by side comparison of code clones can easily be performed directly from the code clones results window. Select 2 clones or a group containing at least 2 clones. Right click to select compare. Just the code clone fragments are compared using the built in diff tool. 



Action
A results window with medium clone match shown. Select 2 code clones. Right click, select Compare. Show that the fragments do not textually match, but were still detected.

Dialogue
The Code Clone tool isn't just a simple text comparison. It's a real analysis of the semantic tree. The detector will match fragments where variable names have been completely changed. It will find matches where some statements have been reordered. 



Dialogue
Code clone detection is very valuable. It increases maintainability and lowers the costs of code changes.