NDepend is a Visual Studio extension that helps you analyze your .NET projects in a multitude of ways. One big feature, is that it allows you to generate reports that visualize the solution and its various dependencies, which can give you a better understanding of what you’re working with, and how various parts are connected to each other. Another interesting feature worth mentioning, is the fact that NDepend lets you query your own code for information using a Linq like language called CQLinq. With CQLinq you can perform queries that retrieves all of the methods that has over 20 lines of code for example, and the ability to query your own code in that way can be quite handy when you’re working with larger solutions.
I’ve only scratched the surface when it comes the various code metrics that NDepend allows you to create for your code. One such metric is “Cyclomatic Complexity” — which can measure the complexity of a single method, or even a whole class. In order to get actionable insight from the tool, one must obviously take some time to understand what all of those code metrics actually mean, and what they’re actually meant to measure. NDepend provides definitions for all of the metrics the tool offers, as well as guidelines that will help you decide how to act based on the insights the tool gives you. In the case of cyclomatic complexity, their recommendation states that methods with a cyclomatic complexity higher than 15 — are hard to maintain, as well as hard to understand. Methods with a cyclomatic complexity of 30 or higher — are “extremely complex”, and the recommendation is that you should split those methods into multiple smaller methods.
I’ve only had the tool for a week, so I certainly haven’t learned all there is to learn about NDepend, and what it has to offer. I’m gonna keep experimenting with NDepend, and read up on the various code metrics it provides, so that I’ll be able make real improvements in the code that I’m working with. So far it has given me some insights about complex methods that could get split up, as well as some visual input about a couple of unwieldy classes that should probably be split up as well. 🙂
I’ll get back later once I’ve had the chance to try it out more in depth. If you’re interested in NDepend, the Getting Started page might be a good starting point.