Structure Comparison in Text Compare Tool
Structure Comparison is a mode for the Code Compare text compare tool. It can be toggled using the eponymous button on the toolbar. With Structure Comparison turned off, the application returns to the usual comparison mode.
The following examples can help you better understand the advantages of Structure Comparison.
Moved Code Elements
The first example demonstrates how Structure Comparison can be used to trace code elements movement.
The following screenshot shows comparison of two files using the usual text comparison algorithm:
The code remained essentially the same but two strings were swapped. Default text comparison detected differences in corresponding strings and highlighted them using the preset colors.
With Structure Comparison enabled, the tool compared the source files like this:
The Structure Comparison algorithm recognized the C# syntax and highlighted no difference, since the code would run the same way as before.
The second example demonstrates another practical feature of Structure Comparison — association of renamed methods that contain similar parameters. The method Paint was renamed to Render while its parameters remained unchanged.
The first screenshot depicts comparison using the usual text comparison algorithm.
With no code recognition algorithm enabled, the blocks were treated as totally different ones.
The Structure Comparison algorithm detected identical parameters and treated the Render method as a renamed Paint method, highlighting the difference as a single modified block.
The third example describes the use of Structure Comparison to associate methods with similar names.
Just like in previous cases, when you compare source code using usual comparison algorithm, the blocks are considered absolutely different.
Structure Comparison detected similar method names and handled the blocks as modified. This feature can be especially useful for mistype detection.
Implementation of XML structure comparison has its own peculiarities and is covered in a separate article of our blog.
For details on the major feature set of our file diff and merge tool, refer to the overview page of Code Compare.