Wednesday, November 12, 2003

Being the tools geek that I am it is somewhat a surprise that I have not used FxCop earlier.

Today, I installed it. Two minutes later it spanked my code. Three minutes later I added it to my favourite tools list.

Three words: Use. This. Tool!

FxCop is a rules based code analysis tool that checks .NET assemblies for compliance with the .NET framework design guidelines. It uses call graph analysis, reflection and MSIL code analysis to find non-conformant code sections.

It is very thorough.

When checking method names it verifies that they conform to the casing guidelines (camelCasing/PascalCasing). It knows how to extract the words from method names and checks spelling, too - and it doesn't like the word "foo":

Member name 'Occurrences1Foo' contains unrecognized words. Correct the spelling of the following: Foo was its comment on one of my NUnit test cases.

It finds localization-related issues, which is great news since it is so easy to mess up and many times you will not find the bug until monts later you have a customer on the phone telling you in broken English zat yoor progrem is big wong.

'WordToken..ctor(System.String)' contains the following calls that do not explicitly provide CultureInfo. These should be replaced with calls to overloads that do:


The call-graph analysis is even more impressive: It quickly discovered a nasty bug where a constructor called a virtual method. It showed the call graph that leads to the condition and gave the following advice:

'NGram..ctor(Int32, System.String)' contains 1 call chain(s) that result in a call to a virtual method defined on the class. Review these for unintended consequences :

NGram.update(System.Text.StringBuilder, System.Text.StringBuilder)

Virtual methods defined on the class should not be called from constructors. If a derived class has overridden the method, the derived class version will be called (before the derived class constructor is called).

This kind of error easily slips in when refactoring code, and it is hard to catch if the base class is simple enough that it does not provoke failure in the unit tests. FxCop caught it in less than 7 seconds.

All in all it took mere minutes to convert me into a believer. This is a great tool. Install it, use it and learn from its constant feedback as you write new code. It will not only make you write better code and libraries, it will also help you avoid a lot of embarasing bugs.

Sunday, November 09, 2003

MSDN TV has released a new video featuring Chris Anderson and Don Box giving a tour of Windows "Longhorn" and the new UI model, Avalon - and very briefly, the WinFS integrated storage model which provides an Outlook-like object model for the entire file system.

The show format is an XP pair-programming sessions. Viewed in this perspective it is a great showcase for the high information exchange rate under this development model. Even as a passive viewer, there is a lot to learn - even more so if you are actually taking part. PP is definitely a very productive way of training your colleagues and producing code at the same time.

Avalon is definitely a very promising next step for the windows UI programming model. It combines the highly productive declarative programming model known from HTML to Windows UI definitions, using the XAML (pronounced "samel" to rhyme with camel) language and the CodeBehind model known from ASP.NET. Say good-bye to those long, windy designer-generated code sections and "do not edit" comments.

I wonder if they will eventually unite the Web and Windows UI programming model. Writing a XAML to ASP.NET compiler seems like a feasible project. Time will tell if they go that route.

Indigo, the next generation of web services/remoting API looks very, very cool - notice how little code they need to write to wire up distributed services. Nice.

On the "blinkenlights" side of things note that the whole UI is now vector based so expect lots of eye candy in Windows apps in the future. That will no longer be a Mac specialty.

Connoisseurs will be pleased to note that Don is using Emacs.

On a further note it looks like Slashdot would be Whackdot had it originated in Redmond - at least "whack" is how they pronounce the "slash" or "stroke" character, as the blokes in England would say.

Memorable off-topic quote of the show, a comment on polishing the UI for the app, "Where is you black turtleneck? And you latte? And your Macintosh?"

...well, watch the show and hear it in context. It is much funnier that way:

MSDN TV: Lap Around Longhorn: "Chris Anderson and Don Box provide a code-centric high level walk through of the main pillars of Longhorn. "

This page is powered by Blogger. Isn't yours?