Wednesday, July 7, 2010

On using NDepend

I was recently introduced to try out NDepend which is a Visual Studio add in and pretty much
a code metric and code quality tool to manage complex .net projects / solutions.

After a painless download and install I fired up visual studio 2008, loaded up my template project for a web application, did an analysis and was greeted with an html file with all kinds of reports.

at first it was a bit overwhelming but upon reading the report I was surprised at the information it had about my project.

One of the first things that got my attention was the "Assemblies Metrics", this pretty much tells me how abstract my assemblies are, lines of code, lines of comments, coupling and cohesion. just by having this and running it on every build or release would show how my project is growing and where it's headed.





Next is the Assemblies Abstractness Vs. Instability.
(explaining the chart is another topic altogether but for a primer this document explains it pretty well)

but the main point of the graph are

Abstraction where it would show how extendable your assembly or code is.

Stability where it would explain how dependent your code is to other assemblies or components, this doesn't mean that the

higher the instability the more unstable your code will be but rather how dependent your code is to other assemblies, (more dependent it is the harder it is to change your code.)

if the assembly is not that extensible the more it will go to the zone of pain (this would be pretty normal on end points like web services and wcf services, where it's usual that there would be no virtual methods or abstraction).

the zone of uselessness would show that if your class is too abstract and no other classes depends on it then it goes there.



Assemblies Dependencies Diagram I can't stress enough how many times this could have saved time on my previous projects where a visual diagram would show
class heirarchy and dependencies.








Running up Visual NDepend provides you with the CQL Queries (Code query language), this uses the same syntax as SQL but uses your code base as the database and right now the default code quality metrics NDepend has seems to cover everything I would need to be able to refactor my project properly.

things like Unused codes / dead codes, code quality, naming conventions and Encapsulation are queried, now other products also does this like resharper / FXCop but I like the extensibility NDepend offers. although I'm a bit half hearted on this one since I like how resharper presents the code errors and optimizations while I'm coding, NDepend seems to target more the team lead / architect level where code reviews are done and evaluated.


so far I've only been playing around with this tool for a couple of days and it is quite impressive, This is the kind of tool I would recommend to a company with large projects and solutions where managing source code becomes more and more "challenging" as it grows.

There's a Trial / Open Source / Academic Edition and you could buy the Professional Edition for about US$ 377, the more licenses the bigger the discount (although I'd assume you'd only need 1-2 licenses per project in a company.)

you could also check out their site for tutorials and videos about the product.

No comments:

Post a Comment