DEV Community

Cover image for NDepend – a cutting edge static code analysis tool
Madhu Sudhanan P
Madhu Sudhanan P

Posted on

NDepend – a cutting edge static code analysis tool

Writing code is fun and but writing maintainable code is a challenge and it is much needed for large-scale projects. Manually validating the code quality, maintaining performance and other factors are not feasible and will not help in the long term. This is one of the reasons, the developers are using static code analyzer tools when working with maintaining a large codebase.

I am going to discuss such a static analyzing tool which impressed me. And its many features make code maintainability a piece of cake.

NDepend, a static analysis tool for .NET developers. It is well designed, easy to use, and provides deep insight into your codebase to reduce future issues.

Download and Installation

You can download the NDepend from here. It provides a 14-days trial period with three setup variations to choose from.

Maintain code using Code rules and Quality gates

Quality gates feature helps the product owner or scrum master to daily report on the project status and give insight on the product releases. Many companies are now adopting an agile framework and continuous integration, which enables them to have a deliverable product for each commit and allows companies to have short-term releases. In such environments maintaining code standard is more difficult and manual checking will not help on a large scale and makes work tedious.

NDepend provides a vast set of code rules and quality gates which ensures that each commit abides necessary set of rules before committed in the main codebase.
The quality gate violation or code rule violations could be easily visualized in the interactive dashboard provided by NDepend. An example dashboard with quality gate failure is as follows.

Quality Gate
The violations can be viewed in the Queries and Rules Explorer. The two Quality gates violations are shown in the below image.
Alt Text

Code review

Code review is an important phase in the software development lifecycle. It brings a collaboration of peer developers to review your code to make it better. The role of the NDepend static analyzer tool is inevitable since it reduces many manual works by ensuring various rules.

As a scrum master, I think the following queries of the NDepend must be followed during code review for a smooth and successful release.

  • Find and fix Quality gates violations.
  • Regression issues – Regression issues make the end-user frustrated and reduce trust against the product/service.
  • API breaking changes – Users don’t like frequent changes in APIs as it would bring rework and time-consuming.
  • Dead Code – Nowadays, apps should load and work at high speed, removing dead code would reduce the final product size.

There are many other queries available, these are my own minimal list of queries recommendations to be followed during code review.

Another impressive feature in NDepend is its in-built Diff viewer of the code against its baseline. This helps to view the code changes without leaving the visual studio during code review phase.

Architecture diagram

NDepend allows you to visualize application architecture and dependencies using Dependencies Graph and Dependencies Matrix diagrams.

This help us to understand the coupling between projects. The dependencies are represented by thousands of elements that helps to understand legacy code and its dependencies. I tried this architecture diagram on Blazor Clean Architecture which is as follows.
Quality Graph
Quality Matrix

Reporting

NDepend also provides a customizable Report of the code base analysis in HTML format. The report will contain all analysis details of the code base such as quality gate violations, rules violations including architecture diagrams. The HTML page has an interactive UI that allows you to click and view violations within the report.

Alt Text

Alt Text

Alt Text

Also, the report contains a set of diagrams for our codebase. You can click the required diagram to view it on full screen. For architecture diagrams, I find it easier to use in the visual studio than the HTML report.
Alt Text

Summary

NDepend has a large set of features that help us in various scenarios. I just only covered some of the features I used till today.

If you are looking for a static analysis tool with advanced features and reporting system, then you should give NDepend a try. It is more than a static analysis tool, it’s a ”Swiss Army Knife” for .NET Developers.

Thanks for reading. Happy coding!!

References

https://www.ndepend.com/docs/getting-started-with-ndepend
https://github.com/blazorhero/CleanArchitecture

Discussion (0)