Structure Comparison in Text Compare Tool
Overview
The concept of Code Orientation is what makes Code Compare
stand out from an oceanful of counterpart text compare tools. It
processes source files as code and rests on several foundations, Structure Comparison
being one of them. This method recognizes source files code written in popular programming
languages, namely C#, C++, JavaScript, Java, Visual Basic and XML.
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.
Renamed Methods
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.
Similar Names
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.
For details on the major feature set of our file diff and merge tool, refer to the
overview page of Code Compare.