Using NDepend as an alternative to the Layered Diagram

I have used the trial version of NDepend now on several occasions. In general I use it to get a quick overview of large code bases that I am trying to grasp or I use it as a first step in code reviews. It is an amazing tool.

The latest version 4 includes default rules for validating architectures:

image

This kind of rule can also be validated by the Visual Studio layered diagram. But not everybody owns Visual Studio Premium or Ultimate . You need Ultimate to create the diagrams but you can validate using Premium. With $11.000 for ultimate, $9000 for Premium and $400 for NDepend, NDepend is a cheaper alternative for validating your code against this kind of rule

What I like about the layered diagram is:

  • It is easy to setup
  • It is also a nice way to visualize the layers in your application and their dependencies.
  • With a hack you can validate you code against your architecture every time you compile
  • It is easily included as a build step in TFS build.

So let’s look at how NDepend v4.0 does compare on these points.

Easy to setup.

I already had a project in which I used the layered diagram. For setting up NDepend, I started by adding a new NDepend project to this solution:

image

After clicking another Ok I was up and running NDepend. That was pretty easy. You do get a lot of extras when doing this, another dialog in which you can choose to visualize the code or to explore the validation rules. Default the rules are validated on several triggers.

image

Visualizing application architecture.

The Layered Diagram gives me the following overview, which I like a lot. It not only gives me a certain understanding but also a way of communicating with team members and other technical stakeholders. image

The layered diagram also gives the ability to group a number of projects and draw a single dependency for all projects inside of that group, E.g. in the previous diagram the LayeredSample.Services.PortalUpdatBatch group contains four projects any one of these projects has a dependency on the layeredSample.Core group so instead of drawing eight dependencies, this is shown by a single arrow between the two groups. This is a good thing because the diagram is kept readable. This is a bad thing because observers might miss the fact that there are a lot more dependencies.

NDepend gives a number of useful diagrams out of the box. The Dependency Graph comes closest to what I like.

image

The extra info you get when hover over the projects like file location, lines of code and lines of comments is great. Also the fact that you can make the size of the boxes and lines depend on code metrics like lines of code is pretty useful.

What I don’t like is the fact that you can’t save the layout of a diagram, yes you can save it as a picture but I really would like to be able to save which assemblies I have selected and the position they are placed at. As it is now, changing what the box size depends on, redraws my diagram and replaces all the assemblies that I threw away. That is really annoying, (Patrick Smacchia told me there are plans to fix this in the near future)

Validate at compile time

To do any of the architectural validation at compile time we want, we have to write custom CQLinq queries. I had not written any CQLinq queries before but with the online default rules as samples, the intellisense and the design time compilation it was pretty easy to setup the rules I wanted.  For example I wanted only the Core.Configuration project to call the System.Configuration assembly :

//<Name>System.Configuration Should only be referenced by Core.Configuration</Name>
warnif count > 0

from a in Application.Assemblies.Where(x => x.Name != ("LayeredSample.Core.Configuration") && x.IsUsing ("System.Configuration".MatchAssembly()) )

select new { a, a.Name }

I also wanted none of the Core Assemblies to reference any of the service assemblies.

// <Name>Core assemblies should not reference any of the service assamblys</Name>
warnif count > 0

from a in Application.Assemblies.Where(x => x.Name.Contains("LayeredSample.Core") && x.AssembliesUsed.Any(y => y.Name.Contains("LayeredSample.Services")))

select new { a, a.Name, a.AssembliesUsed }

Rules for single dependencies you want to ensure or forbid are made very easily by opening the dependency matrix, clicking with the right mouse button on any dependency  and selecting “Generate a code rule from this”

image

Marking a rule as a critical rule makes the NDepend indicator turn red when it is violated during compilation. It is only too bad that Visual Studio still reports that the build has succeeded even after breaking critical rules. I could find no way to accomplish the build to fail with a local build.

The rules I have build here for NDepend as well as the Layered Diagram are very solution specific. For every project they would have to be created again. NDepend does give you the ability to create more generic rules that you can use over multiple solutions, for details read “Validating Architecture through LINQ query”. Also the out of the box generic rules like “UI should not use DAL” and “Avoid namespaces dependency cycles” are very useful and don’t require any custom code at all.

Including NDepend in the TFS Build.

My first step into integration NDepend into TFS was a bit disappointing.  Looking at the documentation at NDepend it only showed not very detailed steps for integration into TFS2008 and TFS2010, I want to use TFS2012 or TFS Service. Also the recommended way for integrating with TFS2010 is a codeplex project with version 0.5.0 beta 1, not very promising.

But since the documentation for TFS 2010 states that adding a single build step that executes Ndepend.Console.exe with the proper parameters should do the trick it should be possible to do the same for TFS Service or TFS2012. I tried it for both.

  • started by creating a team project and adding my sources to this project. Next step was to create a new build definition with a new process template based on the default process template.
  • Next step was adding a folder to my project called lib\build, placing NDepend complete in that folder and adding this to source control.
  • Added the Ndeped .ndproj file to source control.
  • After that added an InvokeProcess activity to my new build template in the …. section. Based on this post and this post. And calling the NDepend.Console.exe with the parameters described in the NDepend documentation I got it to work with a lot of trial an error

image

image

 

Invoke Process properties:

Property Value
Arguments SourcesDirectory + "\Source\PortalUpdateBatchUltimate.ndproj /OutDir " + BinariesDirectory + "\NDepend /InDirs " + BinariesDirectory + " /silent"
FileName SourcesDirectory + "\Source\lib\build\NDepend.Console.exe"
Result ExitCode
WorkingDirectory SourcesDirectory

Conclusion

NDepend is an amazing tool and in this blog post I don’t do justice to all it can do by just comparing it to the “Layered Diagram”. If you want to quickly get a feeling for an existing code base, or when you do want to de reviews or if you want to keep on ongoing eye on the quality of the code base NDepend is a tool you definitely want in your tool belt.

If I get to a project that has Visual Studio Premium or Ultimate I will be using the Layered Diagram for this kind of validation, it is just too easy to use and the visualization and validations are adequate for the job. This does not mean that there is no room for NDepend, it still offers enough other added value.

In a project without Visual Studio Premium or Ultimate but with an NDepend license I will use it for these kind of architectural validations.

In a single project without Visual Studio Premium or Ultimate and without an NDepend license I don’t think that the architectural validation on it self is enough to buy NDepend . I do think that in any organization there should be a few licenses present that can be used for multiple projects to keep the code quality up to standards.

This post was inspired by this programmers exchange question and the free nDepend version I got from Patrick Smacchia.

References:

Review “Developing applications for the cloud”

Developing Applications for the Cloud on the Microsoft® Windows Azure™ Platform

A while back I started reading the Microsoft Patterns and Practices eBook “Developing applications for the cloud, on the Microsoft Windows Azure Platform.” Now I finally got around writing down some of my thoughts on this book.

When I started reading the book my first thought was “strange”, when I got deeper into the book, my thought was “strange” , when I finished the book, my thought was “strange but informative”

The initial “strange” was from the fact that it is an eBook you can buy but you can also read it completely free online. Since even the pdf can be downloaded for free I don’t really see why you would buy the eBook.

The second “strange” was because I could not find a clear audience for the book. It goes from high level functional to low level development to low level infrastructure to business case. Every audience can get value out of the book and gain initial understanding but also every audience will skip parts just because they won’t find it interesting,

 image

imageimage

In the end the missing clear audience and free online content remained but I also gained a lot of knowledge from the book. With a fun writing style that is combined with low level technical detail ( might need some changes since Azure is evolving rapidly) it gave me some new unique insights on how to think and reason about cloud applications.

In the end I highly recommend reading the free online version of this book. With the technical details for which you have to wonder if they still hold true and the parts that you probably want to skip I think it is just not worth the money.

This review is done as part of the O’Reilly Blogger Review Program. O’Reilly provided the book but does not make any judgment on the content of the review.

Exploring ASP.NET MVC application architecture

I am planning on exploring how to architect a good MVC application. During this exploration I found some interesting web-resources. I might be using this post in possible future blog posts as a reference.

Sample apps

I really think that looking at other peoples code can give you great ideas about what to do and what not. So here are some sample apps to look at. You could look at SharpArchitecture also as a sample app but I thought that one deserved a paragraph of it’s own.

  • I don’t know Rob Connery personally but you gotta love what he does. StoreFront, is his sample app. And you can find a lot about it here.
  • Read the separate Oxite paragraph for more details before downloading ! Oxite got a lot of bad credits but combined with the critics you can find it still has value in learning how to architect an MVC app or how not to architect an MVC app.
  • NerdDinner is rather basic but still is a nice starter with a free chapter of the “Proffesional ASP.NET MVC 1.0” book coming with it.
  • Codecamp server is on my list to explore, haven’t seen it yet. Is is part of the “ASP.NET MVC in Action” book.

SharpArchitecture

SharpArchitecture already has an architecture and while exploring it you can get very inspired. As far as I can tell there went a lot of thought in this architecture and for now I see it as a starting and reference point for my explorations.

You can find it here.

Oxite

When Oxite got out it got a lot of criticism, but also a lot of love to make it better. There is a lot to find in the comments about Oxite about what people expect from an MVC app.

  • This tweet from Simone Chiaretta is what most people thought about Oxite when it got out.
  • This post is my all-time Oxite favourite. Rob Connery gives explanations and solutions.
  • Chad Myers is a good second with also constructive comments
  • Although I don’t like the tone, this post still has some great comments.
  • A collection of Oxite tweets

Screen casts

Most screen casts are not on an architecture level, but I do believe that the more details you know, the better you can architect the application. Also you need to be aware that these screen casts might be about different versions of the MVC framework.

Books

  • This post by David Hayden says enough about some books, take your pick.
  • This is a nice Stackoverflow answer about some books.

Miscellaneous

I just had to mention these posts, but did not have a real category for it.

Other posts like this one

You wouldn’t have guessed it, but other people have collected resources too.

I hope everybody has just as much fun as I have exploring this. If anybody has something to add, please do so in  the comments.

Hooking into the world wide web.

Yesterday I taught a developer centric training class for starting in software architecture. During this class we discussed a few information sources on the web. While putting together the mail for the students in which I mention a lot of the information sources, I thought this would make a nice blog post. So here are the links.

 

Online rss readers:                                                                

http://www.bloglines.com/

http://www.google.com/reader/

 

Good rss feeds:

http://codebetter.com/

http://www.infoq.com/

http://architects.dzone.com/

http://nplus1.org/

http://blogs.msdn.com/jmeier/default.aspx (look at the pocket guides )

 

Link collections: (if you don’t want to plough through 320 feeds yourself)

http://www.arjansworld.com/

http://www.alvinashcraft.com/

http://blog.cwa.me.uk/

 

podcasts:

http://www.dotnetrocks.com/

http://www.hanselminutes.com/default.aspx

http://se-radio.net/

http://thirstydeveloper.com/default.aspx

 

screencasts

http://www.dnrtv.com/ (check out the design pattern series with JP Boodhoo shows 63,65,68,71,92)

http://channel9.msdn.com/

http://channel9.msdn.com/shows/ARCast_with_Ron_Jacobs/

 

free magazines

https://www.msarchitecturejournal.com/Default.aspx

http://www.microsoft.com/netherlands/studenten/informatie/dotnetmagazine.aspx (Dutch)

http://selfservice.abonneren.nl/titels/computable/abonneren.html;jsessionid=C7FD65099CA5399EA1133ED3BB9E2C12 (Dutch)

 

msdn:

http://msdn.microsoft.com/en-us/architecture/default.aspx

 

Good site for asking questions

http://stackoverflow.com/

 

Sogeti related sites (I work for Sogeti):

http://dsa.sogeti.nl/

http://www.clemensreijnen.nl/

http://blog.softwarefun.nl/ (not much to read yet J )

 

The list isn’t complete and it isn’t meant to be. I have given people my opml file with 320 feeds (No I don’t read them all completely) and it was just too much. This list is a way to get started.

 

Good additions are welcome in the comments off course.

Software Architecture 2008

This is the first in a two part blog-post about the software architecture 2008 conference in London.
barbican
The two parts consist of:

  1. The conference itself, the conference location and software architecture in general.
  2. Building domain-specific modeling languages

The conference was great, a wonderful location, fantastic speakers and a very diverse audience. The conference was held at the barbican conference centre.

The blog posts are based on sessions from the following speakers:

Still there is a need for defining an architect and defining architectures, the key note and some sessions started with definitions. For defining an architecture there are some pretty good definitions that most people can agree upon.

“The software architecture of a program or computing system is the structure or structures of the system, which comprise software elements the externally visible qualities of those elements, and the relationship among them.”
Len Bass, Paul Clements and Rick Kazman (SEI)
“All architecture is design but not all design is architecture. Architecture represents the significant design decisions that shape a system, where significant is measured by cost of change.”
Grady Booch
“The set of design decisions that, if made wrongly, causes your project to be cancelled”
Eoin Woods
“Architecture is the art of how to waste space.”
Philip Johnson

But when it comes to defining an architect the definitions are less clear and mostly boil down to a list of synonyms or a list of characteristics, skills or activities of an architect.

Synonyms
Enterprise Architecture: enterprise Architect, functional architect, business architect, strategic architect, domain architect, stream architect, …
System Architecture: software architect, solutions architect, application architect, systems architect, technical architect, …
Infrastructure Architecture: Infrastructure architect, technical architect, technology architect, database architect, middleware architect, network architect, database architect, storage architect, …

The characteristics could be distilled out of the key-note. Among other characteristics an architect needs to fight being human. An architect must fight the urge for

  • New and complex solutions (Fashion driven development)
  • Pursuing possible solutions too far
  • Just having faith (Faith based coding)
  • His own habits
  • Resolving every uncertainty right away (sometimes the right decision is to wait)

Most speakers did seem to agree on a certain skill set.

  • An architect needs street credibility
    • A relation to the code (preferably code himself)
    • Have the big picture to code detail
    • Cannot immerse in code completely
  • A solid technical background that isn’t just history
  • Communicator, appreciate other mindsets.
  • Needs design skills
  • Leadership skills
  • Coaching skills

One of things that was most prominent present was the need for architects to be more agile. Philippe Kruchten also held a session on the same topic on the 18th of june . This talk was an initiative by Logica’s guru4Pro and worthy of a blog post in itself. At the software architecture 2008 conference the message was clear. We need to be more agile to create more sustainable software and projects fail because we are not agile enough. To get an idea, watch the presentation from Kevlin Henney and James Coplien at infoq ( Agile Architecture is not Fragile Architecture ). What you could get from the conference, Philippe Kruchten and the presentation is:

On every project ask yourself: how much architecture do I need and how agile can I be to make this project a success !

In the key-note Kevlin Henney mentioned the Dreyfus Model of Skill Acquisition. This model recognizes five stages of skill acquisition.

  • Novice
  • Advanced Beginner
  • Competent
  • Proficient
  • Expert

According to Kevlin Henney at the novice level people try to learn the rules, when people start to be competent they start to bend the rules and finally the expert recognizes that the rules depend on the context. That is why when you a ask an expert architect a question, nine out of ten times the answer is “it depends“.

And yes, the answer always depends on the context.

Kevlin Henney mentions that the emphasis on context is mostly his own (as are his jokes!), as this comes from patterns, but some of the detail and framing has been inspired and influenced by Andy Hunt and Dave Thomas (the Pragmatic Programmers) and Dan North (better-best-practices).

Let’s make a step in becoming more of an expert in software architecture and recognize that also when :

  • you define an architecture
  • you define an architect
  • you write down what the characteristic of an architect are
  • you determine the tasks of an architect
  • you define the skills that an architect needs
  • you determine how agile a project must be
  • you determine how much architecture a project needs

It depends on the context.