I have started using NDepend which, if you do not already know, is a code base analysis tool. I’ve head lots of good things about it, and I thought it was time to give it a try personally.

Installation was as easy as extracting a zip file, and the application was good to run. I noticed application has recognized other tools in my toolset, such as WinMerge, Reflector, etc. automatically.

I decided to run it on a Farsi Library project, which is a WinForm / WPF control library I’ve been working on. There are a couple of views that could help me see how the library dependency is structured. The easiest to learn is the dependency graph view:

FarsiLibrary Graph

The Dependency Graph easily show how you’re assemblies are coupled on each other, and system assemblies. You probably already know this much, just by looking at structure of your Solution (if your solution is a medium size, that is), But there’s much more to this tool than this.

The “Metrics” view information is also very useful. If you have the luxury of a VS.NET “Team System” edition, you’ve probably used the tool already available there, but the “Metrics” view in NDepend is way cooler.

In this view, you can see various information about an assembly (For Methods, Fields, Types, Namespaces, etc). Collected data such as number of Lines of Code, Cyclomatic Complexity, IL Instructions, etc. may be available in VS.NET code metrics, but some others like “Codes not / covered by Test” which acts as code coverage information, is only available in NDepend. The tool can work with coverage information generated by NCover or VS.NET Team System.

Navigating to code is also very easy. As soon as you click on one of the gray rectangles, you’re moved to the type in Class Browser tree window, and by double-clicking the type there, you’re moved to the source code in VS.NET environment.

Farsi Library Code Metrics

VS Code Metrics

The power of this tool, IMHO, relies on its CQL engine and already available queries to analyze your code with. In a nut shell, CQL is like SQL to query the assemblies with type information. For example, if you want to find complex methods which should be rewritten as smaller ones, you can write a query like :

SELECT TOP 10 METHODS WHERE NbLinesOfCode > 30 ORDER BY NbLinesOfCode DESC

Since the Professional version can store custom CQL queries you write, you can later run them on your “Continuous Integration Server” to enforce certain things as simple as naming conventions, or as sophisticated as code quality, code coverage analysis, etc.

So, what are you waiting for? grab a free version, and give it a try.