I have been using NDepend on various project I am working on and there is so much to say that I can’t wait to do a full review because I will make you wait too long. I got a free license and wanted you to know what the tool can do and what were my impression.
First of all NDepend is a tool that analyse your code. It’s huge! Definitely not a tool you can learn in an hour or two. Simply give the tool a solution or project file and start analyzing. You are first presented with a a complete map of your application. By default it shows all your code sorted by the number of lines but you can quickly switch by different kinds of metrics (LOC, Cyclomatic Complexity, IL instructions, Efferent coupling, etc.).
The best part is that you can write query against your code. This feature is called CQL (custom query language). Need to know which method have more than 200 lines of code? No problem. Really. It looks like SQL and is easy to write (I haven’t written any yet, but I’m sure it will prove useful later).
Take a look at this :
// <Name>Methods with too many local variables (NbVariables)</Name> WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE NbVariables > 15 ORDER BY NbVariables DESC
Out of the box, NDepend provide around 200 CQL queries. It has queries to find unused or dead code, find which method are not test covered, naming convention not respected, types with too many methods, ect. Each rules has a short description on what it does and even provide links to more complete documentation if needed. It also has intellisence as if this wasn’t enough.
A cool feature is the dependency matrix. It’s easy to see where is your dependencies.
The tools itself is beautiful, it make us want to play more with it (it does not use WPF, but it appears to).
A lot of features that I haven’t used yet are :
- Compare assemblies
- Code Coverage
- Writing complex custom rules
I recently came across this post entry by Patrick Smacchia (creator of NDepend) that used the tools to spot bugs in an existing code base (http://codebetter.com/blogs/patricksmacchia/archive/2009/06/21/agile-behavior-nurture-knowledge-database.aspx). I don’t know why but this has really struck me and kept it in my favourites. I could write custom query to spot bad practices and potential bugs.
But there is a downside. On a project I worked last year. Every query that has been executed had a warning on it, almost every single one. That’s sad. I almost cried. But I’m fine now. NDepend will help me.
There is so much to say, that it’s almost impossible to cover it all in one single post. I’ll continue to use it and post any relevant information and features that I really enjoyed in the next couple of weeks.

