Analyzing Your Code with NDepend
Tags: programming, testing, coding, devtips
Published: 2018-03-19 20:07:00

---
title: Analyzing Your Code with NDepend
published: true
tags: programming, testing, coding, devtips
canonical_url: http://programmergoals.com/analyzing-code-ndepend/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/f1gt6jzemp9s8jr6ema1.png
---

On your way to becoming a great programmer, you might ask yourself from time to time if the code you have written is actually good code.

Is it robust and maintainable? Does it follow best practices? Are there any parts that might cost you a lot of sweat and tears in the long run?

Fortunately, you don’t have to answer all these questions by yourself. There are tools that do that for you. And one of these tools is [NDepend](https://www.ndepend.com/).

I was lucky to get a glimpse at the latest pro edition of NDepend – thanks to its creator Patrick Smacchia (this is NOT a paid endorsement!) – and fired it up to check a quite small Visual Studio solution – the source code for an online course – and a bigger solution – an [indie game](https://dev.to/_patrickgod/making-story-driven-indie-games-with-no-budget-3dmj) I’m currently working on with Unity.

In the beginning, you already notice, that the analyzing features of NDepend are pretty deep. And I barely scratched the surface.

The dashboard already provides a sweet overview of your whole codebase.

[![](http://programmergoals.com/wp-content/uploads/2018/03/01_ndepend_dashboard_ssl.jpg)](http://programmergoals.com/wp-content/uploads/2018/03/01_ndepend_dashboard_ssl.jpg)

150 lines of code (as I said, a quite small solution…), perfect A rating, but what’s that? A critical rule violation? What does that mean?

A click already tells me everything. And that’s a really great part of NDepend: the documentation. Everything is explained in detail and there are also links provided that go even deeper.

[![](http://programmergoals.com/wp-content/uploads/2018/03/02_ndepend_critical01.jpg)](http://programmergoals.com/wp-content/uploads/2018/03/02_ndepend_critical01.jpg)

[![](http://programmergoals.com/wp-content/uploads/2018/03/03_ndepend_critical02.jpg)](http://programmergoals.com/wp-content/uploads/2018/03/03_ndepend_critical02.jpg)

I can see the debt of this issue, annual interest, the breaking point and also a detailed description of this violation and how to fix it. A great opportunity to learn that stuff and get better at my craft.

As soon as I fix this issue, I can let NDepend analyze the project again and it tells me the differences to the last analyzation. Did the code quality actually improve or not?

Now let’s have a look at the bigger project. I can either open the solution in Visual Studio and analyze it with the NDepend extension or open NDepend itself and let it analyze the solution there. Either way, I see that the project has some more lines of code and, of course, a lot more issues.

[![](http://programmergoals.com/wp-content/uploads/2018/03/04_ndpend_dashboard_forscience2.jpg)](http://programmergoals.com/wp-content/uploads/2018/03/04_ndpend_dashboard_forscience2.jpg)

Funny thing though, a lot of issues actually come from assets I got in the Unity Asset Store. You can easily see that in the code metrics view. Just look at this beast.

[![](http://programmergoals.com/wp-content/uploads/2018/03/05_ndepend_code_metrics_view.jpg)](http://programmergoals.com/wp-content/uploads/2018/03/05_ndepend_code_metrics_view.jpg)

Hm.. maybe they should analyze their code, too.

Apart from that view, you can also have a look at a dependency matrix and a wide variety of graphs.As already mentioned, I’m really just scratching the surface here.

Also, you can define the rules for every issue by yourself. These rules are actually defined in C# code. That’s neat!

To get the most of this tool, you have to spend a lot of time and learning. But if you do so, it can result in great benefits. One thing I had to struggle with is the usability of the tool. Sometimes it wasn’t that easy to get where I wanted to, the back button on my mouse did not work as expected and I wish there was an integration of NDepend that would tell me the issues directly when I work with my actual code – by using some icons on the left, for instance. Or maybe I’m just missing something here?

On the contrary, of course, there is this endless list of features. With that list, you may find issues you would most likely never find without NDepend. Every issue is explained in detail and you can learn to fix all issues with the great documentation provided.

Even [Scott Hanselman](https://www.hanselman.com/) likes it:

> “NDepend is giving me insight into my apps that I hadn’t had before. Once I realized the depth and breadth of the information I was looking at, I was like a kid in a candy shop.”

To sum it up, I think NDepend is a tool for single users or small teams that really want to dive deep into their codebase and analyze the heck out of it. If it’s about debt and deep quality – and you have the time for that – this is for you.

It can already make sense for small projects but might be more useful for really big projects where you have lost track of your codebase. This case is probably more likely to occur in larger companies which could well use NDepend then.

To really get the most out of this tool, you have to deal with it more deeply and for longer. It’s not just installing, watching the graphs and forget everything. But if you do that, you have the chance to improve your code quality dramatically – and learn a lot on the way.

If you need a tool for quick tips and tricks while you are actually coding, other products might be more suitable. You may want to have a look at [ReSharper](https://www.jetbrains.com/resharper/) or simply use the built-in features of Visual Studio. They are often underestimated, although they’re already quite good!

<small><em>Header Image <a href="https://www.freepik.com/free-vector/seo-elements-background_1819019.htm" target="_blank" rel="noopener">Designed by Freepik</a></em></small>

_The post [Analyzing Your Code with NDepend](http://programmergoals.com/analyzing-code-ndepend/) appeared first on [Programmer Goals](http://programmergoals.com)._

---
### But wait, there’s more!
* Let’s connect on [Twitter](https://twitter.com/_PatrickGod), [Facebook](https://www.facebook.com/ProgrammerGoals), [YouTube](https://www.youtube.com/channel/UCq8LldVrjqe61KQttZlLW8g), [LinkedIn](https://www.linkedin.com/in/patrickgod), [Instagram](https://www.instagram.com/_patrickgod) or here on [dev.to](https://dev.to/_patrickgod).
* Get the [5 Software Developer’s Career Hacks](http://programmergoals.com/5-software-developers-career-hacks/) for free.
* Enjoy more valuable articles for your developer life and career on [programmergoals.com](http://programmergoals.com).