Published: 24 Dec 2007
By: Keyvan Nayyeri

Review of the NDepend tool.

NDepend is a code analysis tool written for .NET developers as a standalone application that can be integrated with Visual Studio and Reflector and lets you easily analyze your code and explore variousmetrics. In this review, you'll read about this product and an overview of its major features.

Overview

NDepend is a tool written by Patrick Smacchia, a Microsoft C# MVP from France. This product is a static code analysis tool that provides lots of unique features to analyze your .NET code and assemblies with statistical information and diagrams.

The current version of this product is 2.6.1 and has two different editions with some differences between their features. As NDepend provides some unique features and is written very well andis being used by big companies and software development teams around the world.. Some of the best-known open source projects are using this tool as well: TestDriven.NET, NCover, MbUnit, and Rhino Mocks.

NDepend is a great complementary for FxCop and these two tools are going to be a main part of my development cycle. I use them more and more to make sure I'm doing the right job!

NDepend has had two major versions: 1.0 and 2.0, while there have been several minor versions like 1.0, 1.1, 1.2, 1.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 and 2.6.

Scott Hanselman has a dedicated podcast about Static Code Analysis with NDepend that you can listen to in order to get a good understanding of this tool and its purpose. Moreover, there are some other reviews about this product that you can find in the list of testimonials.

Later in this review you read more about major features of this product. For now, let me give a short introduction to Code Analysis which is the main purpose of NDepend.

In this review, I'm going to highlight some of the main features of NDepend. Of course, this tool has many great features that can't be included in a single review but you can check them yourself. To review this product, I used our open source BlogML project, which is one of the famous .NET open source projects written with C# and .NET 2.0.

What is Code Analysis?

Code analysis is an important aspect of professional software development. Software is nothing but code and code is the fundamental component of this world. When code gets longer and harder, you need to have some ways to manage its complexity and improve it. Code analysis is a technique that lets you analyze code statically and find places in the code that should be improved. It allows you to analyze the dependencies between different parts of the code.

Code Metrics represent the quality of your code. For example, the Lines of Code (LOC) metric is a metric that shows you if you've been able to write a shorter code for a given purpose. In general lower numbers of LOC are better. As another example, Depth of Inheritance shows the level of inheritance between your types. Obviously lower values are better.

Getting Started

You can begin working with NDepend from several starting points. You can open the NDepend IDE directly or use its integrated add-in with the Visual Studio IDE to analyze your solutions and projects. NDepend can be integrated with Visual Studio 2005 and 2008 with an add-in.

Figure 1 shows the start page of the NDepend IDE, which is similar to the Visual Studio IDE. You can create new projects or open existing projects from here.

Figure 1: The start page of the NDepend IDE

01.jpg

Alternatively you can use the Visual Studio add-in to open your projects for analysis. In this case right-clicking the menu of your projects lets you have access to some options to analyze the project with NDepend.

I can simply choose the option to analyze a set of .NET assemblies and then select my BlogML assembly. In NDepend you can choose from several options to begin analyzing your projects. You can create a new project in NDepend or a new project that is initialized in Visual Studio. You can also open an existing project to open a build comparison project. The last option is analyzing assemblies which I use for BlogML project. In this case, I have to make sure that my PDB file is in the same path as my assemblies to be able to get the most benefit from NDepend. Figure 2 shows the Open dialog for the NDepend IDE.

Figure 2: The Open dialog

02.jpg

After opening your project, you see the NDepend IDE opened and showing some analysis information about your project (Figure 3). NDepend also opens your browser and displays a quick review of your analysis project. Although this review is generated quickly, it is long and descriptive and can give you many insights about your code (Figure 4).

Figure 3: Analysis information

03.jpg

Figure 4: Web Report

04.jpg

This report includes everything that you need to analyze your design presented in a friendly and simple way. So far, I've never needed for something it didn't provide.

As you can see, NDepend has a IDE similar to Visual Studio. It consists of several dockable windows. On the left, there is a Class Browser window that helps you see all the classes used in your project. At the same position you can switch to CQL Query Results that shows the result of Code Query Language (CQL) queries that I'll describe in a moment.

At the left bottom side of the IDE there is an Info window that lets you see some information about the selected items in other windows. At the center you have two main windows: Metrics and Dependencies. These two windows are important in your analysis.

The Metrics window shows a visual representation of your projects with diagrams and you can choose the level of representation (Method, Field, Type, Namespace and Assembly) as well as the metric (such as the default Lines of Code option). This window can help you a lot in analysis (Figure 5).

Figure 5: The Metrics windows

05.jpg

The second window, Dependencies, is where you can analyze the dependency between your elements in a visual manner. You can put one item in X axis and the other one in Y axis then view the dependency between them (Figure 6).

Figure 6: The Dependencies window

06.jpg

At the bottom, you see CQL Queries and Help windows. CQL Queries is described later and Help window shows help information about the application.

Code Query Language (CQL)

Code Query Language (abbreviated as CQL) is a language similar to SQL that queries code elements and sections in an assembly or solution or project and is designed for the NDepend tool by Patrick Smacchia.

This language has its own specification but as its syntax and grammar are very similar to SQL, you can use it easily. CQL is integrated with NDepend and is one of its most interesting features. NDepend also provides IntelliSense to make working with CQL easier. Using this feature you can easily get access to information about your code.

For instance, in Figure 7, you see how I can type my query and get the help of IntelliSense.

Figure 7: The CQL Query window

07.jpg

In Figure 8 you see the final CQL query that I wrote to select all methods from my BlogML assembly that could be private.

Figure 8: Final CQL query

08.jpg

I run this query and get its results in the CQL Query Result window, together with some statistic information (Figure 9).

Figure 9: The CQL Query Result window

09.jpg

You can see how helpful a code analysis tool like NDepend can be when you're building a professional application and can't possibly take care of everything yourself!

Compare Builds

The other interesting feature of NDepend its ability to compare two different builds of a project to analyze how it's changed. If I choose BlogML 1.0 and 2.0 assemblies to analyze (Figure 10) then NDepend does the job of analysis for both projects so I can compare them. Actually NDepend does the job that it was doing for one project for both projects now.

Figure 10: Build Comparison

10.jpg

Attractive Points

No one has tried NDepend with negative feedback because NDepend provides everything that you need for your code analysis and is really a unique product.

However, there are some points about the product that are specifically useful:

  • Code Metrics Statistics - NDepend provides a full list of Code Metrics that let you analyze your developed application in a moment. I found this feature very helpful. Even Visual Studio Code Metrics tools can't provide such great details.
  • CQL - Support for Code Query Language (CQL) is really great. When I applied it to pieces of large projects, I, and my code, greatly benefited.
  • Assemblies Abstractness vs. Instability Diagram: This is a diagram that makse me happy when I look at BlogML analysis and see it has a good position in the diagram. This diagram simply compares instability of a project with its abstractness.
  • Assembly Dependencies Diagram: This diagram has been very helpful for me. I've been trying to check my projects to see if they can run on Mono (.NET implementation for Linux). This diagram has helped me see the dependency between my project and different .NET assemblies. Since some .NET assemblies aren't supported very well in Mono, this could help me understand which parts of my projects may not run there. There are many more scenarios where this diagram can come handy.

Licensing

Currently NDepend is provided in two licenses: a trial/open source/academic license which is free with restrictions and a commercial license (Professional license) with full features and good prices. In my opinion, licensing of NDepend is fair and commercial license has a reasonable price.

You can read the editions comparison here.

Documentation

NDepend also has a rich documentation. The application itself comes with excellent help options (can be found in Help menu) and the official site has a good collection of text documentation and starting videos. In general, NDepend doesn't have any problem in this field.

Summary

In this article, we have reviewed the NDepend tool for performing code analysis.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Keyvan Nayyeri

Keyvan Nayyeri is a Ph.D. student in Computer Science and already has a B.Sc. degree in Applied Mathematics. His primary research interests are Software Engineering and Programming Languages & Compilers. He’s also a software architect and developer with a focus on Microsoft stack of developm...

This author has published 5 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


Increasing your productivity with Visual Studio 2010
Visual Studio is the program that most of the times a .NET developer is working with. This article c...
Understanding Multilayered Architecture in .Net
This article focuses on understanding a basic multilayered architecture in C#.Net.
Introduction to Android JNI development Using NDK - Part 1
In this first article of this small series, we will try to delve into the Java JNI inner workings an...
Android for .NET Developers - Picklists and listviews
In this article, I'll discuss how to arrange an Android view where the dominant element is the list....
Introduction to Android JNI Development Using NDK - Part 2
In the first part of this series you've learned the fundamentals concerning Java JNI programming. In...

You might also be interested in the following related blog posts


November's Toolbox Column Now Online read more
September's Toolbox Column Now Online read more
Your code via NDepend read more
MvcContrib version control has moved to GitHub read more
October's Toolbox Column Now Online read more
The DotNetRadio.com site is UP! read more
What needed to be monitored to get better Governance read more
Review: ASP.NET MVC 1.0 Quickly read more
8 techniques to find problems in your unit tests within 30 seconds read more
NDepend and CruiseControl.NET read more
Top
 
 
 

Discussion


Subject Author Date
placeholder Good tool Granville Barnett 12/27/2007 8:52 AM

Please login to rate or to leave a comment.