I first heard about NDepend months ago from Scott Hanselman through one of his podcast. I had the chance to evaluate a professional edition of the tool so here are my insights.
Here is a screenshot of one of our current projects loaded in NDepend.

NDepend's CQL (Code Query Language) is the first thing that caught my attention. It is the one of its main features that I love. It's a query language for code so one can issue statements like:
WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE NbLinesOfCode > 30 ORDER BY NbLinesOfCode DESC
Isn't it great to query your code this way, besides we're all familiar with T-SQL. The previous CQL statement returns the top 10 methods from the loaded application with greater than 30 lines of code. Of course you can exclude generated methods like InitializeComponent (which is a strong candidate for the longest number of lines for a method) by tweaking your CQL statement. By the way, the query window provides intellisense!
NDepend comes with a number of CQL to analyze code organized in the following groups:
- Source code quality constraints (code specific)
- Code quality constraints (IL specific)
- Performance constraints
- Design constraints
- Naming constraints
- Queries to understand code
I will not be enumerating the CQL included in the above groups so I suggest that you download the trial edition and try it yourself. There is obviously some intersection with the FxCop tool but I really never bothered trying writing custom FxCop rules to suit my development standards. Writing Naming constraints rules with NDepend is a breeze and it also supports Regular Expressions.
Some of the rules are relative (applies to some) like the Methods poorly commented (WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE PercentageComment < 20 AND NbLinesOfCode > 10 ORDER BY PercentageComment ASC). Personally, I'm on the side where comments are code smells, one or two liner comments are enough but only for very difficult algorithms, unit tests are better documentation for me.
Visual NDepend also has this metrics view which graphically represents any criteria from number of lines of code such as represented below, to number of methods, parameters, coupling, etc. The bigger the square below means more number of lines of code.

Another feature for the professional edition (not available in the free edition) is the build comparisons. It basically analyzes two build versions, analyze what's been deprecated, broken, etc. It's useful to easily know if an upgrade to a component you're using will break your app. It also provides easy access on the details of what has been changed.
The binaries also include extensions for MSBuild, NAnt and CruiseControl.NET so you can readily include NDepend tasks in your build scripts for your continuous integration setup.
Other statistics that are measured by this tool include efferent and afferent couplings. A complete documentation on the software metrics is found here.
I agree that a static analysis tool like NDepend is great for architects or even team leads who wants to have a quick overview of their project rather than diving into the code and scratch their heads. With it, one can have a bird's eye view on their projects.
Their website provides a number of screencasts so you better check them out to know the whole feature set of NDepend.
Posted
06-07-2007 11:28 AM
by
jokiz