Sunday, April 1, 2012

Juval Löwy's (IDesign.net) Architecture Clinic

Recently I had the privilege of attending the IDesign Architecture Clinic in Sydney. It was a week long intensive mix of the architecture theory, the responsibilities of an architect, and practical coaching.  IDesign runs two similar courses in the software architecture stream: The Architect's Master-Class and the Architecture Clinic. The idea behind the Clinic is to keep the attendee numbers relatively small and have the opportunity to learn from a true master architect.  In Sydney my group was lucky to have Juval himself run the course.

Day one was full on.  Juval gave us a light speed overview of some of the critical material from the Architect's Master-class. The rest of the week was then practical hands-on experience using IDesign's "The Method". Days two, three and four followed the pattern of choose one of the attendee's systems and use The Method to draw up a proposed new architecture. Then Juval and the group will critique. Day five was all about project design, planning, and tracking.

The amount of knowledge and experience imparted during this course was simply incredible.  No other speaker I have ever listened to has packed this amount of information into five days.  There isn't more than a few handfuls of other people in the software industry that have the same level of industry insight and where it is heading in the next 10-20 years. During conversations there were more than a few statements that gave us a glimpse of where the industry is heading.  As a bonus Juval also kindly donated two of his evenings and run us through some other topics in depth, from the Architect's Master-class.

Anyone who has listened to Juval speak will know he is both highly intellectual and controversial. He often makes statements that send murmurs through an audience.  This course was no exception.  Some examples (not direct quotes):

  • Every class as a WCF service.
  • The Method doesn't fit well with Agile.
  • The Architect is the responsible party not the project manager.
  • Most project managers actively kill their projects.
  • Self managing teams don't work.
For most questions the general answer was "there is no time, you need to attend the Architect's Master-class".  Other vague answers sounded as though he was hinting at some future technology now under development but is bound by NDA's. There were some answers, but with anything new and revolutionary every question reveals 3 more.

My personal opinion on this course was that it was worth while (it is definitely not a cheap course), but I would have liked to have completed the Architect's Master-class first.  I also believe that there was too much after-the-fact review based criticism and not enough coaching.  For days two, three, and four we were left to decompose the system and draw up our own plan for the whole day, whereas I would have preferred to have been walked through it from start to completion on day two before the practical on days three and four. Again just my personal opinion, and like I said still very worth while.

So, did I rush back to the office and evangelise all my co-workers and stakeholders? 
No. 
Why?
Because I cannot sell a new idea to my stakeholders without having prepared answers to the questions I know they will ask. Questions like: "We are a Scrum-Software-House, this doesn't fit with Scrum. You are not permitted to undertake projects in this way". Or "We hired you as an Architect not a project manager, you are operating outside your responsibilities". Or "Some of what you are prescribing infringes on senior developers responsibilities of technical design, architects should not be prescribing technical design".  And my favourite: "We don't have enough architects to operate this way and no-one wants to be an architect". The answers to these questions are not the kind you can Google and Juval simply recommends go to the Architect's Master-class.  So I'm filing this learning under "Interesting future insights that can't be used right now".

Can I justify going to the next Architect's Master-class?  
Probably not for a while.  Due to corporate politics its unlikely I can sell another course in the next 12 months just for me given the overall cost of fees, flights and accommodation (planned courses are only in the States). Also given that this one has not set my architecture team on fire with new levels of efficiency.

There's no easy solutions, just broad wholesale change.

Thursday, February 23, 2012

Running Unit Tests in Parallel

Its been possible to run unit tests in parallel for some time now, but it doesn't seem to have taken off. NUnit has had a parallel runner (PNUnit) since 2007, MsTest since 2009. I think running tests in parallel has two distinct benefits:
  1. The test run will complete a little sooner.
  2. It will help to test your system for concurrency issues.
HOWEVER, all your tests must be thread-safe. Writing unit tests that can be run in parallel can be difficult and designing and writing a system that allows parallel unit testing can be even harder. Statics and singletons will be the undoing.

So how do you set up tests to run in parallel?

For MsTest you will need to edit the .TestSettings file with a text editor (or right click in Visual Studio and open with Xml Editor).


Set the number to the number of cores you want to use for running tests. Setting this to a number greater than cores you have in your system will have no benefit. Setting it to 0 will auto-configure and use as many cores as the runner can. Remove the attribute completely to disable.

This will then ensure running the tests from within Visual Studio's Test menu run in parallel. (Make sure the testsettings file you modified is selected as the current active settings file, do this in the Test menu). If you're using Resharper I'm not certain it honour's all the settings in the testsettings file. (I didn't notice any difference with parallel enabled).

Setting it up for NUnit is a bit easier, it simply means you use a different runner. The bad news is that its command-line only with no integration into Visual Studio. See PNUnit for details on downloading the runner.


Friday, February 10, 2012

Optimised binary serialisation and serialisation tips

During some research a colleague of mine (thanks Richard)  has done into serialisation lately, two code project articles came to my attention.

Top Ten Caching mistakes, and
Optimizing Serialisation in .NET

The first one talks about some common mistakes and why they are mistakes and also some mitigation techniques.

The second talks about the problems using XML, DataContractSerialisation (or any text based serialisation for that matter).  Basically, they can be much slower than what you require. Also the binary serialisation and deserialisation process can create unnecessary data.  The article shows a custom binary serialiser that looks very useful.

Friday, January 27, 2012

Using IoC for Extensibility

MEF is probably a better choice if you know up front there is a good likelihood of consumers wanting to extend your application by injecting their own types.  However, I think there are a few exceptions to this rule.

Firstly, most modern software applications make extensive use of IoC to loosely couple dependencies and allow easy unit testing.  Also, sometimes you don't think it is likely someone will want to swap out a class, but don't want to rule it out either.  Building in MEF support for unlikely cases is a waste of time in my opinion, especially if there are ways to override behaviour using the IoC mechanisms you're already using. In these cases I prefer to allow consumers to override the IoC registered types.

I did a post some time ago on how to prevent IoC configuration chaos (refering to the explosion in size of your app.config if you put all registrations in it). This post discusses using code registrations and a mechanism to automatically run the registration code for each assembly on start-up.

This idea can be extended to allow custom extensions to be added.

By default Unity doesn't allow types to be registered that are not referenced by the application (I think Structure Map doesn't allow this either).

Scenario 1)
A consumer of an application that is already fully completed wants to change some behaviour in that application, and they do not have the source code, just the binaries. The application uses the IoC pattern referenced by the blog post above.
The consumer can create a new application project that references everything the original application and basically wraps around it. The new application includes any new  references required to new assemblies containing classes you want to use in IoC registration.  On start-up the new application simply delegates into the original. Now you can customise the IoC mappings in the App.Config of the new application. This works great for windows services, web services, console applications, and some UI applications. This is the preferable scenario.

Scenario 2)
Another option is to customise the IoC pattern described in the blog post mentioned above. When the initialisation process is looking referenced assemblies in the AppDomain, you can add some IO code to scan for assemblies in a folder.  These new assemblies can be loaded with reflection and added into the AppDomain. Once this initialisation process is complete the App.Config can be applied. This is less desirable because the author of the original application has little control over how customisation are used by the original system. Potentially a security risk.
You could modify the reflection assembly loading mechanism to only allow assemblies with a certain signing key for example to mitigate this security concern.