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

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

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

Figure 4: Web Report

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

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

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

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

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

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

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.
About Keyvan Nayyeri
 |
Keyvan is a software architect and developer who has a bachelor of science degree in applied mathematics. He was born in Kermanshah, Kurdistan, in 1984.
Keyvan’s main focus is on Microsoft development technologies and their related technologies such as mark-up languages. He’s also experie...
View complete profile
|
Top Articles in this category
Settings Manager for Windows Vista Sidebar Gadgets
SettingsManager is a JavaScript library that allows Windows Vista Sidebar gadgets to persist common settings that all gadget instances have access to.
SuperToolTip
Office 2007 offers great new features, one of them is the SuperTooltip which provides much more information about controls than standard old style tooltips. This article shows how to build tooltips in such a way.
ORM in .NET 3.5
This article covers a general introduction to ORM concepts, the approach that .NET 3.5 takes, and how it compares to these other packages.
Barcode image generation made easy
In this article we are going to generate barcodes in .NET. Barcode-aware devices, such as scanners and printers, are readily available on the market, as long as the barcodes we generate follow the standards.We will implement barcode generation using Microsoft Ajax in a web application.
Introduction to 3-Tier Architecture
Brian Mains explains the benefits of a 3-tier architecture.
|
|
Please login to rate or to leave a comment.