Today's I was exploring the Visual NDepend Tool which is super-effective in analyzing the code base to figure out and control the complexity of the code. This tool is particularly useful for architects or enthusiasts interested in getting an overall picture as well as detailed metrics of the application. I ran this tool on a sample application which uses the Microsoft Windows Workflow Foundation's Rules Engine assemblies.

For the sake of getting maximum information about the capabilities of the NDepend tool, the sample application that I have is just a POC (badly written with no structuring or layering, without comments and a lot of spaghetti code).

There were several interesting things that I saw in the report. I am going to quickly enlist some of the cool things here:

1. Application Metrics

If you would like to get a quick overview of Number of Lines of Code, Classes, Delegate, Interfaces, Values types, Enums, Generic Type definitions, Comments and even IL instructions emitted as result of compilation then check out the simplicity as well as effectiveness of NDepend below:

image

2. Assembly Metrics

Complementing the application metrics is the assembly metrics which does the job of reporting the Types in an assembly, number of types outside the assembly that depend on types within an assembly (Afferent coupling), number of types within the assembly which depend on types outside the assembly (Efferent coupling) that exists in those types, number of internal relationships within assemblies and so on. This is very effective from architectural standpoint to achieve a correct balance of coupling and decoupling and in turn helps to gain a correct balance of performance vs maintenance.

image

 

3. Assembly Dependencies

The assembly dependencies are also highlighted with the aid of a metrics table as well as a simple yet effective diagram as below:

image

 

4. Assemblies Build Order

Many of us know that when visual studio IDE builds a solution, it has to take into consideration the order of construction so that appropriate dependency assemblies are generate first before the other assemblies that consume those. This report section gives a quick idea about the build order of assemblies and again I think this is a simple yet very useful thing from architecture analysis standpoint and identify possible build issues.

image

 

5. CQL Queries and Constraints

This is where the over-whelming part of the tool and reporting starts. NDepend uses a SQL like querying facility to query practically every possible information of the .NET application independently of the .NET language used to write the application. So for example if one would like to get metrics related to code quality or encapsulation or unused/dead code then this is your key.

Here are is an example of the CQL report: (observe the areas highlighted in a red rectangle) The CQL syntax shoots out a warning if the IL instructions exceed 200 or lines of code is > 30, etc. This is lovely stuff.

image

6. Types Metrics

Lastly there is smart types metrics table available that gives quick information on various things like associations between classes, cyclomatic complexity computed on the code, depth in inheritance tree, etc.

image

 

 

Again these are things that I covered from a reporting perspective primarily because finally the outputs of the tool speak how good or bad a tool is. And I believe this is a great tool for architects to keep a visual control (if I may say) on the code base and it's definitely amongst some of the must have dev tools.

I will provide screen shots and more information on the tools GUI which again is very easy to use (feels like using Microsoft office product :) like Word or Excel with Ribbon and the UI components have been well laid out.

There's one thing, however that I would like to see in the tool is some user friendly help system that is context aware (like the visual studio context sensitive help). Also, I am not yet sure but my version of NDepend navigates to online help for every small thing. I haven't yet been able to figure out if there is a local help installed with the tool and if so then how do I make NDepend point to it instead of navigating online.

 

Overall rating 4.5 out of 5!!! cheers!!!