NDepend Review

Saturday, March 14, 2009 05:39:05


I've been trying out a product called NDepend (version 2.11), a .NET code analysis tool, for the past few weeks. NDepend was written by a Microsoft MVP named Patrick Smacchia, a software developer and author from France. NDepend provides dozens of useful features for reviewing and analyzing your .NET assemblies.

NDepend uses CQL (Code Query Language) as the backbone for its analysis. CQL is a query language based loosely on the SQL standard syntax, and is fairly easy to read and write, especially due to the similarities to SQL (SELECT, WHERE, ORDER BY, etc.).

Some samples of the CQL code:

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

SELECT TOP 10 METHODS
WHERE MethodCa == 0
AND !IsPublic
AND !IsEntryPoint
AND !IsExplicitInterfaceImpl
AND !IsClassConstructor
AND !IsFinalizer


Out of the box, NDepend provides a significant number of useful queries, such as identifying unused members, improperly encapsulated objects, and code quality features like types or methods that are too big or complex. These queries are all customizable - for example, you can change the "Methods with too many parameters" query so that it only returns methods with more than 8 parameters, instead of the 5 that comes by default - or exclude the query altogether. Adding queries to the analysis is just as easy - just write a CQL query and add it to the project.

In addition to the CQL query results, NDepend provides a few visual representations of the projects. The dependency graph is a diagram that shows each of the assemblies in your project, along with their relationship to one another. The size of the boxes and thickness of the edges represent properties of each assembly, such as number of lines of code, or code complexity.

NDepend Dependency

The metrics chart is a little more difficult to make sense of. It displays fields, methods, types, or namespaces as little boxes inside assemblies, with the sizes representing one of several metrics, like number of IL instructions or number of members. When dealing with large projects, the sheer number of types makes this collection difficult to look at. However, if there are any significantly large methods, types, etc. in your project, that may tend to jump out at you and give you the opportunity to review your code architecture.

NDepend Metrics

Once your NDepend project is ready (or you select a quick project and go with the defaults), you can fire it up, and it takes all of your CQL queries and graphs, and writes them to an HTML report, complete with query results, warnings, and summary information. This report is a great starting point for improving your project and customizing your queries.

There are plenty of options out there when looking for a code analysis and verification tool. In my opinion, what makes NDepend unique is how truly customizable it is, based on the CQL specification. Other code analyzers may allow you to build your own rules, but they typically are all based on what the tool wants you to be able to check. With CQL inside of NDepend, you, as an architect, can decide what's important to you, and query for it, regardless of whether anyone else thinks it's important.

I would definitely recommend NDepend for anyone interested in analyzing and improving their codebase.

Tags: review programming tech

Comments:

Add Comment

About.Me Facebook Twitter Google+ Stack Overflow LinkedIn FormSpring YouTube Yelp