CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Patrick Smacchia [MVP C#]


Diff tools to see source files changes

 

Making easy to compare 2 versions of a code base is something that I consider super important and that is why it became a major feature of NDepend. While source file repository tools (a la VSS or CVS…) also provide this feature, the great thing with NDepend is that changes are not considered just as text file modifications. For example you can dissociate code change from comment change and from structural change with these 3 CQL queries:

 

SELECT METHODS WHERE CodeWasChanged

SELECT METHODS WHERE CommentsWereChanged

SELECT METHODS WHERE VisibilityWasChanged

 

…and there are plenty of others trick supported, to see what is not used in a tiers assembly or to see how the coupling has been impacted by code changes. These are summarized in this 3mn screencast

 

Often knowing where the code was changed is not enough, you want to see what was changed by comparing older and newer versions of source files. This is useful to focus code reviews on code that has been changed. Doing so is a killer practice to rationalize code reviews and make the most of it by often pinpointing subtle last-minutes bugs. Empirically, I came to the conclusion that the bulk of bugs are luring inside the code that is not yet in production, in other words, the code that has been refactored or added since the last release. I wrote an article on this topic: How to avoid regression bugs while adding new features 

 

NDepend used to rely on the good old WinDiff tool to compare 2 versions of a file:

 


 

One of the most common feature request we got was to support any source files diff tools. Thus we added this as an option, with a list of the most popular text diff tools available:

 


 

Notice that we want to make sure to provide a flexible support for any diff tool with the command line arguments tags $OldSrcFilePath$ and $NewSrcFilePath$. Thus, the list of tools is here to make it more convenient to bind NDepend with your prefered tool but you can still choose any tool outside the list. We also provided the tags $OldSrcFileLine$ and $NewSrcFileLine$ but surprisingly, none of the diff tool we tried support these command line arguments.

 

It was quite interesting to churn the web for the most popular diff tools. It seems that some free tools, especially WinMerge, sustain the comparison with non-free tools. There are some passionate debates around which diff tools to use, such as on the Jeff Atwood’s blog that praises for Beyond Compare. There is also a feature I was not aware: You can compare 3 versions of a file. This seems to be supported only by KDiff3 and Araxis Merge. One of the must-have feature that most of tool supports is the ability to compare recursively 2 folders to see which files have been deleted/added/changed.

 

Frankly, I haven’t tested thoroughly all tools. At first sight, Araxis Merge seems to be the most featured one with an impressive list of features and I found it quite easy to grasp. However this is also the most expensive one.

 

The main difference that I have found between free and commercial tools is on how the tool got polished. By polish I mean things like: Is it localized, How smartly the command are organized, Startup time, On-Line and Embedded Documentation, No UI Freeze or user wait, No pesky crash, How cleverly the UI real-estate is used, Options persistence and sharing.... However, let’s mention that the freeware WinMerge is really polished.

 

As the team lead of a commercial tool for .NET developers, I found that indeed polishing a software is the best (and only) way to extend the set of users from the enthusiast/early ones to the (much bigger) set of potentially interested users. For the development team this is also a great satisfaction to be allowed to spend time on all minor but important details. This is usually a burden list that tends to grow. There are always numerous features in the pipe to add but when the minor-TODO list gets shortened, you'll notice a lot of positive energy and feedbacks.

 

After this digression, it is maybe worth providing the list of tools we found:

 

 

Finally, I noticed a free diff tool that comes with an intuitive presentation of changes but unfortunately it is only available on Unix. Kompare:

 


 

Here is a list of dream feature sets for diff tools (in praise of Beyond Compare) but personally, such a simple and intuitive way to browse changes could make me prefer one diff tool over the super-polished ones.

 



Comments

Rob Cannon said:

# April 28, 2008 7:12 AM

Yann Schwartz said:

Hi Patrick. I

concur with Rob. DiffMerge is a really nice free - as in beer - tool. I've switched from WinMerge to DiffMerge a while ago. The 3-way diff is peculiarly nice.

# April 28, 2008 7:29 AM

Patrick Smacchia said:

Thanks for this useful feedback,

the v2.8.1 has just been released but be sure that DiffMerge will be referenced by the Diff tools list of NDepend within the next version.

# April 28, 2008 7:55 AM

Yann Schwartz said:

You could also make it possible to add a custom diff tool, since the command line options are pretty generic and it wouldn't be too hard for a user to add it himself.

# April 28, 2008 8:22 AM

Patrick Smacchia said:

Indeed Yann, it is possible to link with any other diff tool and I just added:

Notice that we want to make sure to provide a flexible support for any diff tool with the command line arguments tags $OldSrcFilePath$ and $NewSrcFilePath$. Thus, the list of tools is here to make it more convenient to bind NDepend with your prefered tool but you can still choose any tool outside the list. We also provided the tags $OldSrcFileLine$ and $NewSrcFileLine$ but surprisingly, none of the diff tool we tried support these command line arguments.

# April 28, 2008 9:10 AM

real estate options said:

Pingback from  real estate options

# April 29, 2008 5:29 PM

pipe supports said:

Pingback from  pipe supports

# May 3, 2008 2:58 AM

Sam Gentile said:

Identity Management/OpenID/Security/P2P/WCF Scott Hanselman has a great post on OpenId P2P and WCF: Some

# May 5, 2008 7:37 AM

atwood tools said:

Pingback from  atwood tools

# May 12, 2008 2:25 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Patrick Smacchia

Patrick Smacchia is a Visual C# MVP involved in software development for over 15 years. After graduating in mathematics and computer science, he has worked on software in a variety of fields including stock exchange, airline ticket reservation system as well as a satellite base station at Alcatel. He's currently a software consultant and trainer on .NET technologies as well as the lead developer of the tool NDepend which provides numerous metrics and caveats on any compiled .NET application. He is the author of Practical .NET2 and C#2, a .NET book conceived from real world experience with 647 compilable code listings. Check out Devlicio.us!