Disclosure: I received a free license to NDepend
I know about NDepend (www.ndepend.com) for a very long time, I believe that I heard about it and read about it from the day it got its name. even though I knew it, I never spent the time to really use it and I never really understood why should I use it.
this all changed in the last few months. you see, I got a free license and that was the trigger to a very good friendship between NDepend and me.
NDepend is a tool that allows you to investigate your code base. it holds a list of rules that you can run against your code and get different metrics to help you diagnose areas where there might be a problem and an indication about the quality of your code.
You can run NDepend as part of visual studio or a standalone application.
This is how it looks after I ran NDepend against one of my projects with the standalone application
What is it good for?
There are a few use cases that I found NDepend to be very very good for. you see, as a consultant I usually have more than one project that I’m working on, and sometimes there might be a long time that I can’t attend a project because I’m traveling or lecturing.
to maintain control over the quality of the project and to make sure that the guidelines that we set are being kept inside the team, NDepend really comes in handy.
NDepend holds a really full and long list of queries and rules that it tests your code against.
After you run the NDepend analysis on your code you get values for each one of the rules.
for example, in the picture above you can see that NDepend found that I have two methods that are two complex
if we click on the rule, we can drill down and see what are those methods and what was the exact score they got
But what is the score means? one of the greatest things of NDepend is that although it is so comprehensive, it gives great documentation for every rule or feature. when I click on the rule I can see the full query it makes together with explanation and link to a very detailed page that describe everything about it
The NDepend queries are written in a language called CQLinq (Code Query Language). CQLinq is a LINQ-based language that allows you to make queries on the types, assemblies, methods and everything in the code object model of your project.
With CQLinq you can create new queries to add to the NDepend project so that you can keep test your code with rules that are relevant to your domain.
here is a simple CQLinq query that checks that all the methods inside some namespace has low Cyclomatic Complexity
from m in Application.Namespaces.WithNameLike("ProductName.FeatureA").ChildMethods()
where m.CyclomaticComplexity > 10 select m
When you create a NDepend project and run analysis on your code, NDepend will remember the results you got, so next time you run the analysis you can see if improved or not.
on the NDepend dashboard there are various graphs that let you see how your project is look as the time goes
I Really like NDepend and there are many more features I haven’t mentioned here such as the ability to attach it to you CI and generate reports or visualizing your project with wonderful charts and graphs.
I recommend you to try it yourself and see what new insights you can discover on your project.
NDepend is a great addition to your tool belt and will be invaluable tool when you starting to work on a new project or learning an existing one.