Advanced Code Diff with VBDepend

Advanced Code Diff.

This document explains how to use the VBDepend build comparison features, in the context of the interactive UI.
The document Reporting Code Diff explains how to use the VBDepend build comparison features, in the context of reporting.


Code evolution and code maintenance are some of the most prominent characteristics of software engineering.
VBDepend comes with some advanced code evolution and code diff features. One of the coolest results of VBDepend, is that now, developer benefit from several fine-grained code diff features, one click away from their natural developing environment. Let‘s expose 3 typical code diff scenarios.

▲▲ Go to Top ▲▲

Code Diff from within VisualVBDepend

So for example one can right-click a project in the Code Browser and ask for Select Methods (of the project) where Code was Changed.

This will result in a CQLinq query generated that Select Methods (of the project) where Code was Changed. Naturally, for each method listed, one can jump straight to source code declaration or ask for diff.

▲▲ Go to Top ▲▲

Code Change Review through Search Panel

The Search Change Panel is actually just a CQLinq query generator related to Code change. For example, in the screenshot below, we can see that asking for Method + Change + Code was Changed or was Added generates the CQLinq query:

from m in Application.Methods 
where m.CodeWasChanged() || m.WasAdded() 
select new { m, m.NbLinesOfCode }

The result shown is ideal to do efficient Code Change Review: not only all code changes are nicely organized at a glance, but for each methods refactored, the developer is just one click away to observe diff in source files.

The Search Change Panel’s options offers various possibilities to explore diff, including searching for code elements where code and only code (not comment) was changed or where comment and only comment was changed, where visibility was changed, where was added or removed etc….

A bonus option is to search diff in tier code, like asking for which library types is not used anymore for example.

Typically, developers like to write tests for testing automatically refactored and new code. Another cool bonus option is to search for diff coupled with code coverage by tests ratio, like asking for methods where code was changed (i.e refactored methods) and where it is not actually properly covered by tests.

▲▲ Go to Top ▲▲

Defining the Baseline for Comparison

Earlier in the post we introduced the concept of Baseline for Comparison. This represents the previous snapshot version of the code base against which, the comparison is done. Typically, the Baseline for Comparison represents the latest version of the code in production.

The Baseline for Comparison can be specified through the menu: Diff > Define The Two Snapshots to Diff > Define the project’s Baseline for Comparison. The dialog below appears and let chooses through different options to define the baseline. The Baseline for Comparison option is then persisted in the VBDepend project file.

Finally, any diff tools can be plugged through the menu Diff > Source Files Compare Tools (this is something explained in details in the post Diff tools).

▲▲ Go to Top ▲▲