Thursday, May 28, 2009

The Future Of WinForms... What's changed in 2010? (Thanks, NDepend!)

What follows is a review of NDepend via an analysis of the changes between .NET 2.0 and 4.0 for the System.Windows.Forms.dll.

A question came up on the Forums earlier today asking about the future of WinForms. There are some people who have been thinking that the WinForms project has been completely abandoned at Microsoft. Well, according to NDepend, There are the following changes between .NET 4.0 and .NET 2.0 as it applies to System.Windows.Forms.dll:

213 types were changed, and 9 types were added.
596 methods were changed, 50 were added, and 8 were removed.

How did I get this info? First, get a copy of Patrick Smacchia's NDepend program. Next, after installing and starting up, of course, remove the .NET folders from the list of default folders listed in the program. Do this by going to Project Properties -> Code To Analyze, and clicking the "View Folders" button...

After opening the list of folders, remove all of the listed folders.

Next, click the Browse button to browse to the location of the System.Windows.Forms.dll assembly, which is located, at least on my machine, at C:\windows\assembly\gac_msil\System.Windows.Forms\\System.Windows.Forms.dll. To trick the OpenFileDialog, I had to paste this directly into the file textbox on the dialog.

Then run an analysis. (Oh that magical moment...)

Immediately after running the analysis of .NET 2.0 System.Windows.Forms.dll, change the project properties, and removed the 2.0 version of the assembly from the list, and add the 4.0 version, which was located, on my machine, at C:\windows\assembly\gac_msil\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll.

Run another analysis. (Can you feel the joy?)

Once that's completed, on the Compare ribbon, click the Build Comparison button. This is what should show up...

Select the build date on the Older Build, the first analysis you performed, and leave the Newer Build's date the same. Completing it all, click OK, and then open the Compare ribbon again. This is where it starts to get cool...

Click the "Search Change" button, and you'll be greeted with something like this:

Using the buttons listed at the top, you'll easily be able to analyze the code to see what's been added, removed or changed since the last build. As you can see, there are 9 types listed as having had been added. So, it doesn't look as though there've been a ton of changes done, but there have been some.

After performing this exercise, I got to thinking.... How can I use this in my own projects?

The comparison feature within NDepend is the best code-comparison feature I've seen so far. It's quick, simple, and enables me to give hard metrics regarding the changes between builds, and analyze the additions, changes and removals of methods and types. If you keep (rebase) the previous versions of the files in a separate location, you can even compare the source files. Being able to see the changes between builds is a very powerful mechanism especially when working in a team environment, where changes need to be monitored, and complexity needs to be managed. When a new bug is introduced, it's nice to not have to use TFS History lists to hunt down the code that's changed, but rather to simply view what's changed since a particular date and time.

One important thing to note about the product, is that you're going to get the best use of NDepend when you use it every day. Code can change pretty quickly, especially in teams, and NDepend (nor any tool for that matter) has the ability to detect whether a change happened last week or two weeks ago, if the only reference points it's given are from today and sometime last month. If you really want to reap the power of the application, use it daily.

I could go on about what's great about this product, but there are several other people who have written excellent reviews. Just search "review of NDepend" on Google. You'll see several examples of the (extremely unique) Metric view, as well as the very concise CQL Query language, which allows you to select certain combinations of code metrics to use in your project.

NDepend is a very powerful tool aimed at developers who want to do more than "get it done" when it comes to their work, and are truly aiming at excellence in their design and implementation details. I encourage you to check it out.

All that said, I'll leave you with an image of the System.Windows.Forms.dll as represented in the Metric view, organized by IL Cyclomatic Complexity.