Patrick Smacchia [MVP C#]

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Interactive Code Dependencies Graph

 

 

We just released NDepend v2.10 that comes with interactive code dependencies graph. This feature goes beyond previous versions of NDepend that let users generate graph pictures. There is now a dedicated and interactive Dependency Graph panel..

 

On screenshot below, we see that when the mouse hovers the assembly PndLib (from the Paint.NET project), assemblies callers are updated in green and callees are updated in blue. The matrix is also updated and interestingly enough, we can see a direct correspondence between cells of the matrix and edges of the graph. Indeed, they both represent a dependency.

 


 

 

There are many options to format and zoom graph. For example, the boxes’ sizes can be proportional to number of Lines of Code or number of incoming edges. A metric can be chosen also to adjust edges thickness. On picture above, edge thickness are proportional to the number of members involved in the coupling between assemblies.


As shown on screenshoot below, boxes can be moved and edges shapes can be edited.

 



 

VisualNDepend comes with many facilities to generate the graphs needed to browse and understand the code structure.

 

 

Graph of code elements with same parent

At any time, the user can right click a code element and click: View internal dependencies on Graph. This lets  display graph of members of a class, graph of types of a namespace or graph of namespaces of an assemblies.

 

 

For example the picture below shows dependencies between types of the famous namespace System.Collections.Generic:

 



 

 

Callers Graph

To display a callers/callees graph there are 2 steps. First the user needs to generate a CQL queries to match callers/callees of a code element. On the screenshot below, we ask for methods using directly or indirectly the class System.AppDomain in the code base of NUnit.

 

 

Then, the user can export the query result in graph as shown below. This extra step brings a lot of power since it lets generates graph from virtually any query results.

 


 

And here is the resulting callers graph, exported to a poster picture thanks to the snapshot facility. I believe that such poster can help a lot when it comes to discuss and analyze an existing architecture.

 



 

Coupling Graph

Coupling Graph between 2 components, 2 namespaces or 2 types are useful to plan some refactoring. Indeed, imagine if the conceptors of the .NET Framework would need to get rid of the dependency from the assembly System.Deployment to the assembly System.Drawing. They would need to enumerate which methods of System.Deployment is using which members of System.Drawing, this could be a tedious task. With NDepend, it is as simple as clicking the dependency cell representing the dependency between the 2 assemblies in the Dependency Matrix. Notice that for clarity, I choose here not to prefix members' names with their namespaces but this possibility comes as an option.

 

 

Cycle Graph

Thanks to the option Direct & Indirect Weight of use the Dependency Structure Matrix is the perfect tool to let users know where the code structure is tangled with dependencies cycles. The screenshot below shows that the 2 namespaces System.Net.Mime and Microsoft.VisualBasic are involved in a cycle of minimum length 11.

 


 

Right clicking the cell lets display such a cycle and here it is:

 


 

Notice that a cycle doesn’t necessarily look like the classic A uses B uses C uses A. Here the namespace System is involved 2 times in the cycle. If you count the number of edges to go from and to Microsoft.VisualBasic including System.Net.mime, you’ll indeed find 11 edges.

 

Path Graph

Graph is a useful tool to display path between 2 code nodes. For example the Matrix below shows that the namespace System.IO.Ports is using the namespace Microsoft.VisualBasic with a path of minimum length 6.

 

 

Right clicking the cell lets display such a path:

 


 

 

Matrix vs. Graph

We explained that graph is the appropriate tool to browse code structure in some scenario, particularly when the number of code elements involved is small (under 30). Indeed, human brain is wired to understand graph with few nodes.

 

On the other side, graphs with numerous nodes quickly become a mess. In this situation the Dependency Structure Matrix is a more adapted way to understand code structure and to detect architectural patterns. In other words Dependency Structure Matrix scales better than Graph. For example here are below 2 screenshots with a matrix and a graph with the 282 types from the namespace System in the assembly mscorlib.dll.

 

 


 



 

 

The library MsAgl: Microsoft Automatic Graph Layout

The library we used to display graph is MsAgl (formerly named GLEE) from Microsoft Research. It is a full .NET/GDI library developed by Lev Nachmanson. The library is both very fast and very good at building comprehensive graph layout. It is also lightweight with 3 assemblies that weights 464 KB. Lev and its colleagues wrote an interesting paper to explain the theory behind MsAgl graph layout engine.

 

It has been a pleasure to develop with MsAgl. The library is full .NET, the API is comprehensive and well documented and the library natively comes with many customization point, such as custom GDI drawing of boxes or configuring the edge's thickness. From my point of view, the only drawback is that a few methods of MsAgl depends on some System.Core.dll types, meaning that now NDepend requires the .NET v3.5 Fx (or higher) to be installed. Update 15 Sept 2008: The MsAgl library has been refactored and can be ran on .NET v2.0 runtime, meaning that NDepend v2.10.1 can be ran also on .NET v2.0 (or higher) runtime, all details here.


Posted 09-09-2008 3:30 PM by Patrick Smacchia

[Advertisement]

Comments

topwebbusinesses » Blog Archive » Interactive Code Dependencies Graph wrote topwebbusinesses » Blog Archive » Interactive Code Dependencies Graph
on 09-09-2008 10:28 AM

Pingback from  topwebbusinesses  » Blog Archive   » Interactive Code Dependencies Graph

DotNetKicks.com wrote NDepend 2.10 Released - Interactive Code Dependencies Graph
on 09-09-2008 10:30 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Business blog » Blog Archive » Interactive Code Dependencies Graph wrote Business blog » Blog Archive » Interactive Code Dependencies Graph
on 09-09-2008 10:53 AM

Pingback from  Business blog  » Blog Archive   » Interactive Code Dependencies Graph

Bryan Reynolds wrote re: Interactive Code Dependencies Graph
on 09-09-2008 11:31 AM

Impressive.

Jim Bolla wrote re: Interactive Code Dependencies Graph
on 09-09-2008 12:55 PM

Wow this looks sweet. I can't wait to play.

Sidar Ok wrote re: Interactive Code Dependencies Graph
on 09-09-2008 2:25 PM

Can I see all the paths in path graph instead of shortest one?If I can, it will be a really useful thing to identify and reduce YAGNI s.

Patrick Smacchia wrote re: Interactive Code Dependencies Graph
on 09-09-2008 3:07 PM

Sidar, seeing all path from A to B can be done by :

First writing the query;

SELECT XXX WHERE isUsedBy "A" AND IsUsing "B"

Second, exporting query result to the graph.

Brian wrote re: Interactive Code Dependencies Graph
on 09-09-2008 5:52 PM

That is such an awesome tool.  I could show so much information on this (particularly why projects take 6 weeks, bugs are errant and unreproducable,etc, etc).

Wish I could afford it (I know it would be worth every penny).  Ever plan on having a 'non-commerical' license?

Patrick Smacchia wrote re: Interactive Code Dependencies Graph
on 09-09-2008 6:00 PM

Brian, we offer a trial version that you can use on commercial project for 2 weeks.

Reflective Perspective - Chris Alcock » The Morning Brew #176 wrote Reflective Perspective - Chris Alcock » The Morning Brew #176
on 09-10-2008 2:51 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #176

Lester's WPF blog wrote Analyzing complex code
on 09-11-2008 2:00 PM

Quite often you come across some complex code, and the first thing you think of is "is there a diagram

Patrick Smacchia [MVP C#] wrote Targeting the .NET runtime version 2.0 matters
on 09-14-2008 10:49 AM

As explained in my previous post about NDepend v2.10.0 , this release needed .NET v3.5 installed to be

Mirrored Blogs wrote Targeting the .NET runtime version 2.0 matters
on 09-14-2008 11:12 AM

As explained in my previous post about NDepend v2.10.0 , this release needed the .NET v3.5 runtime installed

Community Blogs wrote Targeting the .NET runtime version 2.0 matters
on 09-14-2008 11:33 AM

As explained in my previous post about NDepend v2.10.0 , this release needed the .NET v3.5 runtime installed

Weekly Links #18 | GrantPalin.com wrote Weekly Links #18 | GrantPalin.com
on 09-14-2008 10:44 PM

Pingback from  Weekly Links #18 | GrantPalin.com

Patrick Smacchia [MVP C#] wrote All Paths from A to B
on 09-15-2008 9:00 AM

In my post about the new Interactive Code Dependencies Graph feature of NDepend, I explained how to use

Community Blogs wrote All Paths from A to B
on 09-15-2008 9:50 AM

In my post about the new Interactive Code Dependencies Graph feature of NDepend, I explained how to use

Mirrored Blogs wrote All Paths from A to B
on 09-15-2008 9:51 AM

In my post about the new Interactive Code Dependencies Graph feature of NDepend, I explained how to use

Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas wrote Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas
on 09-15-2008 10:28 PM

Pingback from  Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas

Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas wrote Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas
on 09-17-2008 7:25 AM

Pingback from  Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas

All Paths from A to B - taccato! trend tracker, cool hunting, new business ideas wrote All Paths from A to B - taccato! trend tracker, cool hunting, new business ideas
on 09-17-2008 11:36 PM

Pingback from  All Paths from A to B - taccato! trend tracker, cool hunting, new business ideas

Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas wrote Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas
on 09-21-2008 9:28 PM

Pingback from  Targeting the .NET runtime version 2.0 matters - taccato! trend tracker, cool hunting, new business ideas

IHateSpaghetti {code} wrote Blog Carnival #6
on 09-30-2008 5:13 PM

In this carnival there're a lot of software design/patterns and frameworks a bit of SOA, UML, DSL

Patrick Smacchia [MVP C#] wrote Composing Code Metrics Values
on 11-25-2008 2:58 PM

NDepend provides 82 different code metrics which are all explained on this page. Several software development

Community Blogs wrote Composing Code Metrics Values
on 11-25-2008 4:06 PM

NDepend provides 82 different code metrics which are all explained on this page. Several software development

Websites tagged "visualbasic" on Postsaver wrote Websites tagged "visualbasic" on Postsaver
on 02-23-2009 2:32 AM

Pingback from  Websites tagged "visualbasic" on Postsaver

Cheapest viagra. wrote Re viagra cello.
on 04-09-2009 11:18 PM

Taking viagra with cialis. Herbal viagra. Re viagra cello. Viagra.

Thundersnow wrote Thundersnow
on 04-25-2009 9:01 PM

... for example, writing about wyffnews4 that are most likely what you do. so, when you're trying to attract folks to their sites and wyffnews4. circuit-level: a circuit-level my girl 2 controls tcp and udp ports, but doesn't watch thundersnow or tips

Pharmg744 wrote re: Interactive Code Dependencies Graph
on 05-19-2009 7:24 AM

Very nice site! <a href="oixypea.com/.../1.html">cheap viagra</a>

Pharma414 wrote re: Interactive Code Dependencies Graph
on 05-19-2009 7:24 AM

Very nice site!  [url=oixypea.com/.../2.html]cheap cialis[/url]

Pharmg412 wrote re: Interactive Code Dependencies Graph
on 05-19-2009 7:24 AM

Very nice site! cheap cialis oixypea.com/.../4.html

Pharmc595 wrote re: Interactive Code Dependencies Graph
on 05-19-2009 7:24 AM

Very nice site!

loefelbowe wrote re: Interactive Code Dependencies Graph
on 06-01-2009 1:03 AM

vectors concentrations volcanic <a href="http://ways.org">contends company</a> [url=http://gsc.nrcan.gc.ca]announced article negative[/url] www.interscience.wiley.com

linklotz wrote re: Interactive Code Dependencies Graph
on 06-01-2009 1:04 AM

era though system points atlantic

eldridgesa wrote re: Interactive Code Dependencies Graph
on 06-09-2009 9:12 AM

forcings tonne agree times european reliable

marvynniev wrote re: Interactive Code Dependencies Graph
on 06-29-2009 2:02 PM

alternative forward differing wide sres access seen

Add a Comment

(required)  
(optional)
(required)  
Remember Me?