A few months ago Patrick Smacchia a C# MVP and the author of NDepend approached me to take a look at his product: NDepend.
I must admit until than I never done anything with it.
Nevertheless, after I checked the request was really from Patrick, I started to think about it and decided to do it, because:
A.) I felt honoured to be asked;
B.) I was curious if this product could be of value to me
A short overview of the area's NDepend focuses on, I took the area's from NDepend's site:
|Conventions, Rules, Constraints
||Design, analyse and enforce your code conventions, naming guidelines and coding standards
|Code Structure, Design, Dependencies
||Know and control the design and structure of your code base
||Design rules to avoid breaking changes, only review changed and newly added code
||Report over number of lines of code, increase testability and readability, coupling, dead code, design flaws
||In general, but more important of newly added and refactored code, also it integrates with MS Visual Studio and NCover
|Build Process / CI integration
||NDepend is designed to integrate with: CruiseControl.NET, VSTS Build Server, Nant and many other CI or Build tools
This list already shows that NDepend is more than just a dependency tool. Sure it can help you get an insight into the dependencies of your app or code base, but it is much more than just that.
It can help you get a deep understanding of the design and structure of any code base real fast, so if you are in the consulting business like me, this tool can really help you to get up to speed fast.
Also it can help you enforce design and coding standards, not only in the case of problems, reviews or in consulting gigs, but you can integrate it into your CI an/or build process, to get your code base to live up not only to your (quality) standards, but report about them to your clients and/or users also!
Now we know how valuable this tool is in theory, let's find out how it perform's in the real world.
So I installed NDepend, installing in the case of NDepend is nothing more than copying the files onto your harddrive and you are good to go!
I really like this approach, no registry hacks, no dependencies on stuff you do not want on your system, just the 16,6 MB of files and the .NET Framework 2.0 or higher (pic. 1).
Picture 1: NDepend Files
When we start it up it looks quite familiair to the Visual studio user (pic. 2):
Picture 2: Ndepend start page
I think the UI is made with the help of DevExpress controls (http://www.devexpress.com/Products/NET/Controls/WinForms/Bars/), so the app has dockable windows like we know and love from Visual Studio and MS Office. NDepend is skinable. In this post I started out using the default skin, but from picture 9 (Dependency Graph) on I use another skin. When I load the first assembly I must admit that I experienced exactly what Scott Hanselman describes in his post about NDepend.
The first 10 minutes of NDepend is the hardest. It has to click first. There's the whole "what the hell am I looking at" process, often followed by the "screw this" declaration, followed by a quick uninstallation and a sense of "what happened."
For this post I use the Enterprise Library 4.1 and I am going to analyze the DataAccess Application Block by selecting all dll's and .pdb files in the bin directory of the application block's source folder and dragging and dropping them onto the NDepend assembly grid (pic. 3).
Picture 3: Ndepend drag and drop assemblies
After we dropped the grid (pic. 4) shows the assemblies that we dropped onto the grid.
Picture 4: Ndepend drag and drop assemblies
When I click on OK, NDepend starts it's magic, after a minute Internet Explorer is loaded with a report that contains all information on the project and the NDepend start page (pic. 2) is replaced with multiple dockable windows, containing multiple windows that present information about the codebase in their own way (pic. 5).
Picture 5: Ndepend First analysis
While the analyzing takes place NDepend shows what it is doing in a for Visual Studio users very familiair way.
The Visual Studio Output Window and the error list rolled into one. It looks the same and it behaves the same. The window in picture 6 shows what NDepend is doing and what the results of it's actions are.
Picture 6: Ndepend Error list
NDepend calls this the Error List (familiair?). Because of the complexity that NDepend is dealing with, I think that the familairity with Visual Studio is a good thing. If you are like me, deep inside you know that static code analysis is necessary, but it can get really overwhelming. Making NDepend familair helps getting over the initial "why do I need all this?" feeling, it does not completely remove it, but it helps. In other words: IMO this approach is good .
As shown in picture 5 left the 'Class Browser' window is shown, again exactly like we are used to in Visual Studio, the NDepend 'Class Browser' shows a treeview with all classes and their methods, properties, interfaces and fields (pic. 7). Not exactly the same, but close enough.
Picture 7: Ndepend class Browser
Everything in the NDepend UI is context sensitive, by that I mean wherever you select an item in a list or in a picture the other windows of NDepend show data that is relevant to the selected item.
This window (pic. 8) puzzled me a lot at first. what am I looking at?
It is a visual way of showing the codebase, all elements are shown as grey rectangles. which are grouped into a rectangle which is the assembly or class. all methods and members are grey rectangles inside the class rectangle. The rectangles are bigger if they contain more lines of code. You can hover over them with your mouse and information (names etc.) is shown in a context sensitive way. Again, the other windows react to these changes and show data accordingly.
Picture 8: Ndepend Metrics
The Dependency Graph (pic. 9) window shows an image that is a visual represantation of the code base (or selected part of the code base!).
Picture 9: Ndepend Dependency Graph
Again it is context sensitive, if you select some class or member in another window, the content of the Dependency Graph changes accordingly and when you hover over a class in the Dependency Graph, the other windows react to this change.
Picture 10: Ndepend Dependency Graph context
The Dependency Matrix shows the coupling of the classes in the code base. It shows exactly how many methods and fields are used between all classes.
Picture 11: Ndepend Dependency Matrix
Picture 11 shows that 74 methods of Microsoft.Practices.EnterpriseLibrary.Data are using 71 members of Microsoft.Practices.EnterpriseLibrary.Common, so green are methods and blue are members.
By right clicking on an item in the matrix a contect menu is opened where several actions can be chosen.
Picture 12: Ndepend Dependency Matrix contect menu
CQL QUERIES WINDOW
In this window (pic. 13) the CQL Queries can be selected. When selected the query is done during the analysis. The queries are grouped. NDepend comes with a lot of pre-defined queries. They are called queries for a reason, Patrick Smacchia created his own query language called CQL (Code Query Language). With this language it is possible to query code. CQL is the heart and soul of NDepend, it makes NDepend flexible and extensible. It is possible to create your own groups and CQL queries.
It goes too far for this article to go into detail, but I think it is brilliant to use a query language to analyse code.
Picture 13: Ndepend CQL Queries window
You might think: "real nice that I can write my own queries, but such a query language must be time consuming to learn", and discard this option right away, DON'T! Patrick did not only created his own query language, he also made an editor with intellisense! And it really works, it is really easy to write your own CQL query. Give it a try and you know what I am talking about.
Picture 14: Ndepend Roll your own CQL Queries
While I was working on this article, I came to appreciate NDepend more and more. I think it is a mature and well structured tool.
The integration with NCover, Reflector, Visual Studio 2005 and 2008, CruiseControl.NET, VSTS Build Server and Nant are impressive.
It also provides the possibility to choose another code editor over Visual Studio, all these integration possibilities make it very strong, because no matter what your preference is, NDepend will work with the tools you work with.
The UI provides all functionality needed, but I hope that in the future we get a WPF based version of NDepend. The Windows forms UI and the DevExpress dockable windows provide all functionality, but in this day and age I just expect that slick look and feel.
Because NDepend focusses on static analysis only and does this very well. The use of CQL, the query language created to query code is brilliant. Every weird aspect that you need to report over in your codebase is possible through this language and it's editor with intellisense.
The way all windows show information about the code base in their own unique but comprehensive way is exactly what you would expect from a tool like this. The way all windows react in a context sensitive way to selections or changes made in other windows, gives me the feeling that this tool is created with a professional in mind and makes it a pleasure to work with NDepend.
My thoughts exactly...