Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

Treating Code as Data: NDepend

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Nov 2018CPOL3 min read 2.3K  
Treating code as data: NDepend

Introduction

A few weeks ao, a friend of mine recommended a tool and he described it as such.

Treating code as data, you can query information about your code and keep track of changes.

What he said was an understatement. I tried said tool and I found out that it can become invaluable for long-term projects and managing team development. So I’m glad to have a look and talk about NDepend, and my experience with it.

Going through the documentation, I won’t rehash that here since it’s written quite well, but I will describe the functionality I found useful so far.

CQLinq, Querying Code

The main mechanism behind NDepend is the CQLinq language in which you can write C# Linq queries that run through your code to interrogate the number of lines, complexity, number of parameters, number of methods and many more metrics you can extract.

So if you know how to write a Linq query, then it is quite easy to adopt this feature, spare for some specific keywords only present in this tool like warnif, failif and others presented in the documentation. But that’s not all, considering that the tool comes with more than 300 such queries already written, you have quite a few examples to work with, plus the prepackaged queries can also be modified to best suit your needs.

The reason why I call this the main mechanism is because not only can you query for issues, types, methods, classes, but these queries can also be aggregated into gates so you can check your code before pushing it to the production branch, and also for creating trends so that you can follow the changes in the application along its lifetime.

Technical Debt

Embedded into those prepackaged queries or “rules” are some calculations for the technical debt which can be configured via the NDepend Project Properties.

This allows you to see the current status of the project based on what rules were broken during development and how much is the technical debt estimated at if those issues are not taken care of (with interest).

This makes it very handy for any Team Lead or Project Architect that wants to keep tabs on the health of the project overall, and for Project Managers, it can also show an estimated cost in money the debt will incur (especially if it keeps growing).

And the best feature by far is…

Baseline Comparison

So, not only can you extract all that information from your project, from structure to monetary expenses, but you can also create checkpoints along the way.

By building an analysis and then using that as a baseline, you can actually follow the progress of an application as follows:

  1. Create a baseline on the current state of the master or production branch
  2. Start developing on that branch
  3. Create a new analysis of that branch and compare it to the analysis from the master/production branch as a baseline

With this in hand, you could see how many new issues have been introduced into the new code, if it’s properly covered by unit tests, if any debt was introduced into the new branch and what would it cost to fix it should it be allowed through.

Conclusion

I know this has been a short post but this is a big tool and there will be new posts along the way as I find out more and more about it. There are more features I haven’t even touched yet like integration into the build pipeline for your continuous integration, dependency graph and matrix, trends and reports.

When it comes to “using the right tool for the job”, this is surely a tool you don’t want to be without if you’re working in a team or running the project.

Thank you and I hope you will find as much value in this tool as I have.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Romania Romania
When asked, I always see myself as a .Net Developer because of my affinity for the Microsoft platform, though I do pride myself by constantly learning new languages, paradigms, methodologies, and topics. I try to learn as much as I can from a wide breadth of topics from automation to mobile platforms, from gaming technologies to application security.

If there is one thing I wish to impart, that that is this "Always respect your craft, your tests and your QA"

Comments and Discussions

 
-- There are no messages in this forum --