NDepend – a cutting edge static code analysis tool
Tags: dotnet, blazor, codequality, ndepend
Published: 2021-05-30 08:50:15

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](https://www.ndepend.com/), 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](https://www.ndepend.com/purchase). 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2dfd7hsb4up79o07w9vm.png)
The violations can be viewed in the **Queries and Rules Explorer**. The two Quality gates violations are shown in the below image.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbv87suosnyq5t5x8gh9.png)
## 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](https://github.com/blazorhero/CleanArchitecture) which is as follows.
![Quality Graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsqk99ovrwf9pfe82e7w.png)
![Quality Matrix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbjz0mg0eajfph2aabki.png)
## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ua5vw8xu9ogs99cqai7x.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5c14abw6ygbe63h2ffb3.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/500m6sv64l906sr0ltk6.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z05gt12zvisrvcjjsd98.png)

## Summary
[NDepend](https://www.ndepend.com/) 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://www.ndepend.com/docs/getting-started-with-ndepend)
[https://github.com/blazorhero/CleanArchitecture](https://github.com/blazorhero/CleanArchitecture)