NDepend: Powerful Static Code Analysis
| November 12, 2019 | in
How do you effectively evaluate a software solution?
This is a question commonly heard in software development. It reminds me of a question posed in Caddyshack, “How do you compare yourself to other golfers?”, to which Chevy Chase responds with, “By height.”
Analysis of a system usually requires a lot of leg work, poring through the code to gain a sense of its structure and risks. The impact of this is so significant that anything we can do to minimize the effort will help.
That is where NDepend comes in. This Visual Studio extension provides a static dive into your code without you having to crack it open. Some of the insights you can gain from NDepend include cyclometric complexity, lines of code, and even dives into methods/classes that potentially have problems (which NDepend provides based on its set of built-in rules).
I have only been using NDepend for a few weeks. But in that brief time, several of its features have me excited about the potential of it assisting me with system analysis. Below are some of the prominent features that have stood out to me.
Below is a visual showing cyclomatic complexity within the eCommerce reference implementation we use in our Software Design and Development Clinics. This view is great when wanting a high-level look at various areas of complexity within your system. As you can see, NDepend has an excellent graph showing the relative complexities of modules within the reference implementation.
While graphics are good for getting a high-level picture of what may be going on, the underlying data is way more useful when you want to begin digging in.
Another view gives us a great visual showing how modules depend on other modules. I cannot overstate how this kind of presentation helps when analyzing unfamiliar systems and illustrating how they are knitted together.
The graphic below shows how all the modules relate. This is amazing. Not only does the grid show where dependencies exist but also how many there are for each relationship. Powerful stuff.
NDepend also provides a list of issues related to code, effectively a list of things you really should investigate.
The features I have shared here just scratch the surface of what NDepend can provide. I know that in the coming months, I’ll be able to really put it to the test. But even in the few weeks I have been using it, NDepend has already proved itself to be a powerful tool for legacy system analysis.
Anything we can use to make source code analysis more “engineering” and less “random digging by flashlight”, the better. Hopefully, we don’t have to judge source code by height.