Tuesday, October 19, 2010

Developer Tools Reviews NDepend

Developer Tools Reviews: NDepend

Recently I have acquired s piece of software called NDepend, which is kinda nice :-) and was asked to use and then review it, so without further to do let's take this baby for a spin.

This is quite a big beast so either this article will be long or I will split it (as I'm starting to know the tool and more  nice stuff can be found later if I learn it)

Let's open InternalClasses some random old build and see what can we find, for reminders this is a code injection library thats used for meta and aspect oriented programming.

Starting Point

After fast install and integration with vs2008 I went on and started exploring what this tool can do for me. I started my project and did the analysis and was prompted with a browser window containing a report.


Now I don't usually use code metrics as I don't agree with most of them, and what's even more frustrating if someone enforces architectural rules according to code metrics, but for starter NDepend has some nice ones out there like IL instructions etc. The metric view is something that I might use someday it records the cool statistics that I like like Lines of code and all stuff regarding IL (those are the metrics I will be only taking into account, for the most part), but so far I need to get used to the view and then take advantage of the data that's presented, but overall this is a great idea.


I have to say that i just love the Dependency Graph, VS 2010 ultimate has something similar (architecture explorer) but the price point is a no go for me, so this is extremely nice feature. It can show where the most code is located in a project, and help to locate the most important part's can be helpful when analyzing legacy code, or opensource project that's need patching, another great thing that this can be used for is documentation.

This graph shows the most complex classes by pointing out the code size and how many dependencies they have, if we go further into "DynamicType" which is one of the most complex classes.

we can see that method creation to inject code with is not actually the most complex part when we dynamicly put IL in there, but the Constructor creation, and the opening the method for creation. The first one is clear it has lots of dependencies and lot's of complex IL emition code so it can go wrong, the second one hoverer has less code but still has lots of dependencies. At the source of all of this is the highlighted on red atomic type called "TypeBuilder" so just in a few clicks we can gain loads of info and trace the complexity, dependency and usage to the atomic levels which in a big projects can really help (try to find atomic I/O operations in a database engine project that has 2k files and 5 mil lines of code and you'l know what I mean).

Code Rules

This is another great feature, before I used FxCop that's also great tool but NDepend wins here by a long shot. Now as always some rules are not that great and I disagree with them but that's ok, the addition of CQL (Code Query Language) rely is cool here and this is the true potential of the code rules, and this so far the best thing of NDepend, by typing (pseudo) sql code we can create our own rules, that define architecture, naming, code, performance, and even define ones from code.

So lets write a query that tells us when code was changed.

WHERE CodeWasChanged 

This is kinda awesome, but Notice: I had some problems with the changes queries, I had to compare them with previous analysis and this still didn't work, but I got it working after some time.

So this is a tiny bump, it would be cool it the tool already known that I want to compare between current and previous analysis by default.

Another little rant is that I wanted to do nested queries or queries like "Show me types that don't implement interfaces" or maybe I don't know how to query what I want as of now. But I'm pretty sure nested queries are not supported at the moment, this would be nice to have :-).


Search can be done through CQL and also by plain typing I must say this works ok, but besides the awesome CQL standard search is nothing innovative but still nice to have. The context menu is that can show who uses the type etc, is helpful yet Ive seen this in another plugins (mine included), but this now comes in one package so having this in one component adds benefits, besides just by looking at the tool my guess is that all of this stuff are using the underlying CQL engine to search the code and that's good architecture.

Ending Words

I know that I barely touched the topic, because there is a lot more to NDepend, but this is so far my first try of this tool and a review of the first day of usage, the diagrams and CQL are the most awesome things in this package for me, and can make our code a lot better, enforce specific rules, track changes and lot's more, it is safe to say that this tool can fix potential problems in architecture and code in yearly stages as well as those late ones where finding potential problems can be close to impossible.

I will probably write another one of those in some time when I will have more examples and documentation and rules developed with NDepend in my next project, so that the article will have a lot more added functional value.

No comments: