When our projects reach a certain size it is very hard to determine the complexity of our code. It gets harder and harder to see the overall picture. It also becomes very easy to introduce unnecessary complexity to parts of our system that we don’t want to. In simple words, it’s easy to get lost. Especially if there are may people working on the project.
On top of many other tools, practices and principles like unit tests, integration tests, acceptance tests, continuous integration, it is static code analysis tools like NDepend that come into play.
The very first time I stumbled upon this fantastic tool was when I was looking for exactly that: a static code analysis tool to show me which one of my modules is connected to(using) another and present it in some sort of visual graph.
But I was soon to find out that NDepend is much much more. I mean there are tons of features there that you can use on a day to day basis in situations where you don’t want to stray off course.
I will examine some of the features that I find very useful in my work, but there’s much more. You can refer to NDepend official website for complete reference.
First of all I like the fact that it is integrated in Visual Studio. You can hook it up(attach) to your project. It will create a .ndproj file in your solution folder and you are ready to start measuring and analyzing.
Second best feature for me is simplicity. It’s as easy as clicking the ‘Analyze’ button. It will create a report for you that is very nicely formatted and transparent.
You also have access to a dashboard in Visual Studio that provides easy access to all analysis.
Code Rules and Code Query
What it does here is that it uses a LINQ-like language called CLinq to do the code analysis with some pre-programmed rules. But it also provides a way for you to create your own.
This one I especially like. It gives you lots of different measurements on code complexity like: Lines of Code, Cyclomatic Complexity, Coupling, Nesting Depth, Rank, NDepend supports them all (and much more).
NDepend also provides some facilities that will help you to detect metric anomalies and to fix your own thresholds. The NDepend UI displays an interactive view of the architecture of your .NET applications. Such a view can be tuned according to numerous software metrics and can be saved in a PNG file in order to let you print posters.
You have all sorts of diagrams to explore your existing architecture. You have a dependency graph, a dependency matrix, Abstractness vs. Instability graph etc. All this helps you see how your code is structured in a nice transparent way. Providing you nice information that you can act upon like design smells, unnecessary dependencies and so on.
This is one also quite useful feature. You can create trend graphs and measure your progress trough time. Being that number of code rules rules violations, lines of code, unit test coverage, max and average values for various code quality metrics. You can see how you have progressed trough time and how much your code has improved, or degraded.
There are also tons of other very useful features of NDepend like continuous integration reporting, comparing builds and code diff, detecting dependency cycles and so on. Here I just wanted to point just some of them out. You can explore more on their website: http://www.ndepend.com/
Hope someone else finds it as useful as I did.
Until next time.