Andrew Stopford's Weblog

da poobah

News

Articles

MbUnit Folks

Old Blogs

The work\life balance and my absence of late.

For the first time in 7 years of blogging I almost managed no blog posts in a month. I (for fun) graphed the last 12 months of blog posts and sure enough the amount of posts has seen a steady drop. I then graphed all the posts I have made on weblogs.asp.net and since peaking in 2004 I have been on a decline ever since. There are several reasons why, but my now near total flat line needs explanation. 

With the work/life balance and my new family growing the balance tips in favour of more time with my family and less time at the computer. As such blogging\writing\opensource and generally all things out side of the day job has gone the way of the pear (i.e I have stopped). I've had a good run, of the 11 years I have been working in this industry all of them have seen me doing things out side of the day job, from blogging, article writing, book authoring and reviewing, to 4 years of user forum support (as a Macromedia Evangelist) and 3 years of open source\MbUnit. I've had time for all these things but things have changed and as much as I love geeking out I won't have Darcey growing up with her dad a stranger. More so, Emma has been for years a 'computer widow' while I was geeking it up, that has to stop.

I came close to closing this blog, I just don't have that much to say anymore. However, Emma convinced me other wise and I'll aim for a couple of posts a month however I may manage none at all.

The design in TDD

Lately I've been drafting posts on my daily commute and post them up in batches (just in case you were wondering :).  

I recall an article (not sure where I read it) about Ron Jeffries and his ability as an 'alpha architect'. Such people are rare, the design they have mostly in their mind with TDD providing a way of slightly reshaping the design and proving the model (in a pair session that can mean validating each other’s ideas). Another kind of folks is the folks that have a general system picture but design a piece at a time with model shaping and validation occurring as they go. Both are no less a way of designing and developing a system but while the 'alpha architect' has considered overall, system considerations and won't introduce design faults, the other folks need to go carefully to avoid those faults.

The point that TDD is a design process seems to get missed, writing tests before your code is only part of the process and not the sum total. The trouble I have found is that the design process tends to be an organic one, a rhythm that you adopt and you’re not aware of what process you’re following. So in this post I am going to attempt to lay out some of those considerations, not sure I will capture them all and you may have your own, leave us a comment with yours.

SOC

A car is not made from one part but many, with each part such as the engine or wheels made up from other parts. Does the engine depend on the door handle or the windscreen wiper blades? No. Each part, object or concern is separated from the rest but is associated in such a way that you can still achieve your aim without any dependencies on each concern. Relating that back to code, if a car class had an internal Ferrari engine object could we create a Porsche car from that car class? If the car class held a reference to an engine object that the Ferrari object was sub class off could we instead create a Porsche sub class and our Porsche car have the right engine? The practice of SOC is really a good OO practice in that you ensure your classes are so tightly bound to other concerns that you losing all the polymorphic benefits.

TDD helps us here in that we look at all of the concerns of the class and how that class behaves in isolation and with associated concerns integrating with the class. If in writing and then developing the test it fails randomly, your setup and surround is heavy or you are forcing the test into a deep integration test then chances are the class and its concerns are bound up too tight and it's a candidate for further refactoring.   

Integration and Isolation

Take your class in isolation, can you isolate it? If you can what are its dependencies, if you’re testing it what kind of dependencies do you need and how deep are they. The more complex it is to take a class in isolation then your likely looking at a smell and some further refactoring is required. TDD forces you into putting a class into isolation and not being 5 levels deep in a system. You’re focused on that class alone and once taken out of context you can really learn if it will hold up.

Jeremy’s most recent post talked about using static and integration styles in your tests, it's a great post and well worth taking your time over. One thing that is worth mentioning about integration is that integration means as light as you can make it. If your using a lot of other actual concrete concerns to achieve isolation then it's a smell, the cohesion between your class and its concerns is too tightly bound. If you can use mocks or doubles in place of the concerns and your class knows no difference, working as it would normally then you’re in a happy place. Sometimes you can't avoid using an actual and sometimes it makes sense but too many and too often would be a smell, finding a balance is half the skill.

Things around

Consider the concerns around the class, what does the class need as inputs, what does it need for its processing and for its outputs. Those considerations would help you decide what you want to mock, double or actual. For example a class adds an entry to a database as a net product, a test (or for that matter another concern making use of the class) does not care how this product occurs; only that it has occurred. It would be a good mock candidate as we are not reusing the db entry further down the test process and as such we only care the method has occurred. If you wanted to emulate some kind of processing or validation, for example loading a collection of data, then a double could be useful. Following the same contract as the actual, the double would be a light weight emulation that the test could use.

Cross Cuts

Cross cutting concerns are (but not limited to) things like logging, security and validation etc. Things that may not be central to the core parts of the class like processing or logic but needed in the general scheme of the operation of the class. If you find your concerns reusing other concerns more and more often than these could be a cross cuts. To aid re-use and isolation you will want to ensure the cross cuts don't affect the SUT when under test. There are several tools are you disposal (such as DI, IoC and AOP) to service the cross cuts.  

Microsoft MVC and MbUnit

You may recall ScottGu's post about the new feature in latest drop of the MS MVC framework that allows you to pick your unit test framework of choice. With Mix08 now wrapped up and the framework released I can show you what the MbUnit templates look like. You will need either MbUnit 2.4.2 or MbUnit 3.0 alpha 2, early previews of these are available if you really like the edge, but more stable drops are coming, with 2.4.2 installed here is what you will see.

When created you would see


The test project depends on the name of your project, for example "myproject" would be "myprojecttests" etc. The project is preloaded with your main project and a referance to the MbUnit.Framework dll. For the moment we have a default test for the controller, which looks like.

using MbUnit.Framework;

[TestFixture]
public class HomeControllerTests
{
    [Test]
    public void About()
    {
        //
        // TODO: Add test logic here
        //
    }
    [Test]
    public void Index()
    {
        //
        // TODO: Add test logic here
        //
    }
}
 
Notice default tests for your about and index page, these match the default about and index controllers. The template only referances what you need so you don't need to refactor out any unrequired referances.

Note that the MVC team has blogged about how to add and use NUnit templates including NUnit\Rhino templates. To save you some steps we have added the templates to the installers, I did an inital drop of the template but Jeff did all the work to make this happen and we would welcome your feedback.

Posted: Mar 10 2008, 09:47 PM by andrewstopford | with 9 comment(s)
Filed under: ,
Vote for generic co\contra generic variance

Back in 2006 I wrote about the co\contra variance  generics support in .NET, fast foward to today and with the last few .NET releases not effecting the CLR this is still missing. I have high hopes the next version will bring some changes to the CLR and to ensure that this happens the change report needs some votes, add yours to parent bug here.

IronScheme

I have been watching the development of IronLisp, a Lisp compiler for the DLR for a while now. A little while ago it was released onto codeplex and more recently the project was dropped and reformed as IronScheme (Scheme being a Lisp variant).  Great to see another language on the DLE, apart from IronRuby and IronPythoin (and LOLCODE :D) I wonder what other languages are targeting it and if MS have a research\compiler program for it yet?

IronMonkey

Todays Flex 3 announcement also carried with it the announcement of an Adobe OSS site. I was looking around the Tamarin site when I noticed the IronMoney project. Being lead by Seo Sanghyeon, an IronPython developer, I at first thought it was an attempt to get ECMAScript Edition 4 running the DLR. However it seems to be an attempt to get IronPython and IronRuby to run on the Tamarin VM. What I can't figure out is why not attempt to run Python\Ruby on Tamarin? I guess in targeting the IL then IronMonkey can execute the assemblies but surely to help better shape the VM in it's support of dynamic languages why not target languages other than ECMAScript?

MS MVC source

With Darceys arrivial this month I've not really being pay much attention to the various announcements. However I went over ScottGu's MVC framework announcement again and something caught my eye.

Starting with this next preview, we are also going to make the ASP.NET MVC Framework source code downloadable as a buildable VS project solution.  This will enable you to easily view and debug the ASP.NET MVC Framework source code.  We are also going to include a license that permits you to optionally make patches to the ASP.NET MVC Framework source code in the event that you run into a bug in an application you are developing with it. 

The license won't enable you to redistribute your patched version of ASP.NET MVC (we want to avoid having multiple incompatible ASP.NET MVC versions floating around and colliding with each other).  But it will enable developers who want to get started building ASP.NET MVC applications immediately to make progress - and not have to worry about getting blocked by an interim bug that they can't work around.

Seems to have been missed and how dam cool is that ! Mind you it does raise a few questions though.

#1 Let's avoid the OSS debate, I know it's all legal etc etc but a block on any kind of patch sharing may cause a lot of frustration. The patched code cannot be shared but the patch it's self could be. Not sure if VSTS or codeplex can work in a readonly form but if the source was obtained that way (and again if VSTS\CodePlex supported it) and patches be created that could then be saved down on codeplex.  If patches can't be shared then you will be reinventing the wheel a lot to overcome issues, with a patch model you will avoid the frustration. Most OSS projects work in a no-commit fasion to encourage devs to follow project standards before allowing commits, these come in the form of patches that are applied by project admins. No stopping folks applying shared out patches to there own copy if they have the means of doing so. I know I am barking up the wrong tree here but it's worth saying all the same.

#2 Does it come with a unit test suite?

Posted: Feb 23 2008, 05:22 PM by andrewstopford | with 3 comment(s)
Filed under:
Kirsty

I'd like to introduce one the newest members of the weblogs family and already blogging it up a storm, Kirsty Busfield. Lady developers in our industry are very sadly a rare thing and those I have met have been dedicated and hardworking professionals who often push at there profession a lot harder than men. Kirsty is no exception, a natural when it comes to software engineering and is a real help with the MVP\TDD drive on our team (more on that later). I am looking foward to future posts and invite you to add her to your reader of choice.

Posted: Feb 23 2008, 04:52 PM by andrewstopford | with 1 comment(s)
Filed under:
Darcey

This is a personal post, some of these seem to escape into feed aggs so feel free to ignore this if you wondering what it's doing in your reader :) 

Three weeks ago I became a dad, the two most imporant events in my life were getting married and my daughters arrival into the world. Emma was prehaps the bravest person I've ever known, for 17 hours she laboured, in an intense amount of pain only for events to conspire and the need for c-section. Through it all, with barely no dignity left she fought. Recovering aftwards she found the strength to get back on her feet and help Darcey adjust to our world. I've known since the day I met her how amazing she is, I could expect any more of a human being to find the strength and will to do what she did and yet she found that. As long as I live I won't forget that day.

So now I am adjusting to life as a Dad, it's very intense at first and Darcey despite struggling with a little wind and colic is as good as gold. She is gaining weight every day and from one day to the next seems to change. Every day seems to bring a new climb up the learning curve but Emma just seems to breeze through it, heres to my amazing wife.

The coders cave

Our house lately has been a mine of change, 2 new windows, 1 new boiler, and stripped/paint/wallpaper 2 rooms (including the nursery) and retiled the bathroom. I did this all with the help of my family, I do enjoy DIY but depend on the guidance of my dad for the tricky jobs (like fitting a window frame). This explains some of my absence lately, working to a deadline before February and baby comes, ready or not. This has meant nearly all our rooms have been revamped apart from one, my cave.

It was bound to happen, all the rooms were sparkling in the new year but the cave remained. Emma was soon asking me to sort it out and faced with what was really a mess I made a start. Now caves are pretty much something every geek should have, it is your sanctuary, your refuge. It is a place where you can lock in your zone and code without interruption or hassle. To truly do your thing this is where you come. In my cave, by day when no one is in I have the music up on loud and by night I use headphones. Music takes out background noise, I have been coding to it for years as it blocks out talking, phones and other crap. I tend to eat, drink and even on occasion sleep in my cave. A typical cave day starts in the morning with coffee, with trips to the kitchen for more coffee. I tend to eat elsewhere so I don't end up with half of it in my keyboard but coffee is the stable drink in my cave. My cave has a window, a view is all important. It allows you to pause and think but I am also terribly nosey and like to see what is going on as the world passes by :) Having a baby is going to change all of that but for now this is how I live in my cave.

The biggest problem is my cave has horded a lot of stuff. Caves are supposed to, but after a while it gets messy and you run out of space. My cave has so many spare pc parts it is like I killed and ate a giant pc. My biggest problem is books, I am a book junkie, a complete and utter lost case and collect books on just about every subject from GA's to cooking and by authors from King to Sells. I am a complete King junkie and having consumed everything he has written (short stories, Bachman and all) have started to read that other horror suspense master, Dean Koontz and have been chewing my way through his books at a rate of knots. Alas nerd books suffer with the content getting dated and my .net 1.0 books are mostly so dated they are of little value. So I started the task of reducing books, packing them into boxes (just can't bring myself to sell them) for storage. Gaps have opened up and I found myself first in my local borders (coffee in hand) checking out books and then checking prices on Amazon. Buying nerd books is something I struggle to do now. While I consume any knowledge I can the cost of books and the rate the information they contain goes out of date means I have a hard time justifying it. I tend now to treat buying books as a very rare thing and pick books that will stay topical for a long time and are so packed full that I can take my time with my consumption. Repopulating my cave is something I won't do in full but with my new found space I will enjoy picking some really great books.

More Posts Next page »