NDepend is one of these tools, that I have ever wanted to try out, but somehow couldn’t find the right moment to do so. Quite recently, I’ve eventually decided to give it a shot and I can honestly say that I’m very impressed with the outcome.
This tool provides so many statistics and analytics that I’m still wondering what else can be checked in terms of .NET projects complexity, structure, layering, readability and other important things which in the end make a real difference between the great, good, average and poor software.
Since I’m working on an open source project Warden, I’ve decided that it will be my “battlefield”, simply by its very nature – being open source, means anyone can browse and compile your code, therefore you’d rather keep it neat & clean, so that other folks don’t have to swear or yell when they deal with it.
To start your journey with the NDepend, just download the trial version – within 14 days you’ll decide whether you really like it or not, so that’s a good deal. You can use NDepend within Visual Studio or run as a standalone application – I’ve chosen the latter.
So, let’s start the VisualNDepend.exe and load the assemblies that we want to analyze.
Next, click on this green arrow (play) button and wait for a second. Hold it… Hold it… Ok are you ready to face your code complexity?
I can’t say that Warden is perfect, yet it’s not that bad either. As you can there’s a lot of stuff going on, and that’s just one of the many available views (however it’s probably my favourite one) where you can see some very important notes, tips, violated rules and so forth. But what’s even better, is that you can expand the selected query, and see exactly what is the causation (left panel). And within that panel you can click on a selected class or interface and you’ll see a new instance of Visual Studio being opened and ready for the code improvements.
Going further, what else do we have here? Oh, this one, so called heatmap is pretty cool, I like green and it’s very green in here, so I guess it’s all good.
Speaking of green, I might be not that terrible programmer after all. What you can see here is the expanded list of the queries. I didn’t violate the following rules in that case, that’s why you can see so many green circles. Well, that’s definetly something that builds up ones ego.
And hey, how is it going with the dependencies? Is my solution a big ball of mud or any other architectural disaster? Luckily it is not.
So what do you do with all of these metrics? I guess that you already know the answer – start refactoring your code. I’m not saying that I follow all of the rules and take into the heart some of the violations (e.g. I have an abstract class that doesn’t end with Base suffix or I like to keep the interface and its default implementation within a single file) but there were many of them that had to be fixed, just to mention a few like too long and complex methods or mixed namespaces (e.g. class existing within A.B namespace referencing another class from C.D namespace).
Eventually, I did some (actually, more than some) refactoring to the Warden and released a brand new version 184.108.40.206. And you know what is the best part? I did this on Saturday morning 25.06.2016 and 1 hour later (I’m damn seriuos, it was an impeccable timing), the one and only Scott Hanselman has tweeted about the Warden project (seems that he has found my email that I’ve sent to him quite some time ago), as a result my Twitter was literally about the explode (I’ve gained so many new followers and likes that was hard to believe).
Therefore, I’d like to thank you NDepend team, as I could’ve performed some important improvements before my open source project went really viral!