Today I have installed NDepend for the first time! I was really convinced because of this short video and the 7 minute version. Too bad that it isn’t really a human voice, but the feature set of NDepend will make up for that. I followed these instructions for the installation and installed the Visual Studio Add-In.
All I had to do was select NDepend –> attach new NDepend project to current VS Solution. NDepend immediately showed that two critical rules are violated!
- Method too complex (well some programmers might see this one as a compliment, but this does affect maintainability and scalability of your code)
- Methods with two many parameters
so just two issues, I am flattered!
When you click on the ‘Show CQL Explorer’ You will see the Code Query Language which is required to select the critical rules. So you can simply navigate to the issues.
FXCop vs. NDepend
As you all know, you can also choose to use FxCop to check your source code against a coding standard. Here is a link where you can see how you can check your code for the use of the object ‘Arraylist’ instead of the generic ‘List<obj>’ http://www.binarycoder.net/fxcop/html/ex_usegenericlist.html
With NDepend this can be done with CQL like this:
SELECT TYPES WHERE IsDirectlyUsing "System.Collections.ArrayList" [more]
CQL (Code Query Language) is great. You can read more about it here: http://www.ndepend.com/CQL.htm Like SQL is for relational databases, is CQL for selecting source code. The default rules that NDepend uses to validate your source code are divided in several categories. You can enable rules (CQL) disable the rules that are less important according to you. You can add your own rules or edit the default rule set. Here is the rule for one of my two violations:
The CQL even has syntax highlighting!
I recommend that everybody checks out the NDepend trial and go see it for yourself. You can check out the license costs of NDepend here. For developers who work with continuous integration like Cruisecontrol.net, Teamcity or Microsoft Team Foundation Server, it is really recommended to check your code against a code standard.
Let me know if you have NDepend best practices in the comments! Looking forward to it. NDepend is together with Resharper my favorite Visual Studio add-in.