Visual Studio Regions are Evil

I’m yet to see the point of them. For those that aren’t familiar with them, they’re a preprocessor directive that means inside your C# code you can write:

#region Propertiespublic String FirstName { get { return “Paul”; } }public String LastName { get { return “Ingles”; } }

Then, inside the Visual Studio editor, you can expand or collapse whole regions of code.

In principle it’s the same as turning away and not looking directly at the big smelly pile of stuff, but rather cover it up in something that makes it look neater, or like not looking at your bank balance when you login to your online account.

Screen displays are pretty large these days, certainly enough for most reasonable pieces of code. So, the fact you need to put stuff in a region is not stopping-the-line, it’s a work-around. Rather than addressing the problem - you’ve got a big pile of code that could be more organised in code - by say, refactoring and improving the design, and thinking more about roles and responsibilities of classes instead of just dumping stuff places because that’s what’s being passed around). Instead, you organise your editing experience. Lovely.

It’s like Edit & Continue in the debugger, if you’re going to need to edit code as you debug, you’re spending too much time with the debugger.

Wii Rule

I don’t normally post stuff which isn’t development related, but after such a fun evening I couldn’t resist.

I popped into the Virgin Megastore on Oxford Street last Friday to purchase a copy of Singstar for a barbecue and party I was going to over the weekend.

Well, just inside the store were a few small boards advertising that they now had Wii’s in-stock. I headed upstairs to the game department to buy Singstar and as I was paying asked whether they still had any. They did, and a few minutes later I’d bought a Wii, an extra controller and a copy of Wario’s Smooth Moves.

I’ve never had so much fun playing on a games console before. After a particularly stressful day I ‘unleashed the fury’ in a surprisingly competitve game of Bowling with my flatmate. It was a very cathartic experience, plus I won 3 games to 2 :). Following that, our other flatmate broke from his work and joined us to play Baseball. He howled with laughter the first time he moved the controller around to see his Wii Mii making the same movements on screen. Watching one person throw to bowl, and the other then following shortly to swing for the ball was particularly funny.

As for Wario Smooth Moves, it’s the weirdest game I’ve ever played but also insanely addictive - pumping your hands up and down to pop the balloon, and moving your hands back and forth in a sawing motion to sweep the floor during a curling game are just 2 examples of the fantastically funny mini-games.

So far I’m thrilled… I can’t wait for the second Nunchuck controller and Mario Strikers Charged Football to arrive and try it out over the Internet.

All in all, probably the games console I’ve purchased and the one which everyone (including a skeptical flatmate) has been incredibly impressed with.

Short Feedback Loops

Short positive feedback loops in software development are important.

Looking at what happened in the past, we can suggest what could be done to improve the situation in the future. It’s fundamental to lean and agile methodologies. Indeed, the methodologies themselves encourage adaptation of the methodologies by teams to adapt the practices and processes locally.

Test Driven Development (and it’s variants and corollaries) are all about this feedback, they help you think about what you’re doing immediately by showing you straight away. For instance, you can decide there and then that you don’t like the name of something (perhaps it turns out it doesn’t describe the intent). Feedback from you using your code can improve how you design your code.

People strive for fast running tests - they help keep developers upbeat. Slow builds sap the patience and take focus away from writing code and introduce unnecessary context switching. Slow tests become a pain, and people find ways to try and get around having to run them. Feedback is discarded.

To my mind, this is exactly why trying to split off the writing of tests to separate developers is costly - tests are a valuable learning tool, they provide a continuous response to you.

Write a nice clean test that results in simple and expressive code feels good, bad test phrasing feels dirty. Take yourself away from the feedback and you lose the opportunity to gain those insights. It may be that you spend most of your time working with developer tests, but having acceptance tests up-front that can direct your effort provide a great communication tool.

Keep yourself close to the feedback.

A Neat Little Rails Testing Pattern

Inside my tests I try and keep everything I need inside the test, rather than depending on too many fixtures. That way I ensure they’re as readable as possible, and more importantly, obvious.

But, take the following example:

def test_total_is_due_now_if_return_is_less_than_14_days  booking =    :customer => customers(:valerie),    :collect_at =>,    :return_at => 13.days.from_now.to_date,    :boxes => 2,    :collection_address => addresses(:one))  assert_equal, booking.final_payment_due_date.to_senddef test_payment_due_14_days_from_now  booking =    :customer => customers(:valerie),    :collect_at =>,    :return_at => 20.days.from_now.to_date,    :boxes => 2,    :collection_address => addresses(:one))
  assert_equal 6.days.from_now.to_date.to_s, booking.final_payment_due_date.to_send

Well, everything’s in the test, but there’s a fair bit of duplication. What would be nicer, is to take the prototype booking above and just override certain values.

Instead we might write something like

def test_total_is_due_now_if_return_is_less_than_14_days  booking = new_booking_with(:return_at => 13.days.from_now.to_date)  assert_equal, booking.final_payment_due_date.to_senddef test_payment_due_14_days_from_now  booking = new_booking_with(:return_at => 20.days.from_now.to_date)  assert_equal 6.days.from_now.to_date.to_s, booking.final_payment_due_date.to_send
privatedef new_booking_with(args){    :customer => customers(:valerie),    :collect_at =>,    :return_at => 15.days.from_now.to_date,    :boxes => 2,    :collection_address => addresses(:one)  }))end

Much nicer (to me anyway), particularly once you start adding more and more tests (and especially validation related ones).

Make a Big Impact in a Small Area

I’ve been re-reading Evans’ Domain Driven Design recently and, whilst reading one night last week on the train home, something stuck.

It is more useful to make a big impact on one area, making a part of the design really supple, than to spread your efforts thin.

Although I’ve been very lucky in working on things I enjoy, over the past week I’ve particularly enjoyed the work I’ve been a part of. We’ve been trying to make some improvements to a section of code that hadn’t had so many tests around it. Initially, these were used to drive a couple of small refactorings to improve the readability of the class and better separate the responsibilities it had.

So, as good developers some fellow team-members earlier sat down to add good tests around the current behaviour to ensure that whilst things were being moved around nothing broke.

And, because my teammates are all excellent developers, they (and me) spent time ensuring that the tests we wrote were nice and small, communicative and focused. During this time we made sure that our tests were treated with the same respect as the rest of our code, keeping them clean and readable. When the test code got ugly, we refactored our tests (and our design under test) to reflect a cleaner design.

We’ve really felt the benefit of all this work. We started a card that involved adding much more behaviour to the same area of the system. The gateway was getting some brains.

We were able to take the nice, focused, behaviour explaining tests they had started and extend and build upon them easily for the behaviour we were going to add. And, by adding some automated higher-level integration tests, we were able to get even more confidence that we were retaining the behaviour we wanted, and adding the new behaviour we needed.

Thanks to the loving care shown by the previous developers those of us following in the footsteps had a much easier time, and our new design is much more consistent, useful, and ultimately valuable.

Because we chose to make a big impact on a very small area of the system, we felt a large benefit on our productivity. Our tight focus helped us evolve a more supple and elegant design.

A Little Capistrano Recipe for Joyent Accelerator

I’ve started putting together some Capistrano goodness to help automate the process of getting a new application deployed onto a Joyent Accelerator using the default Apache 2.2/Mongrel stack.

The first cut is working (for me at least) and I’ve put up a SVN repository at that people can grab the recipe from.

  • accelerator_tasks.rb contains the Accelerator specific tasks. This includes one for creating the Apache 2.2 proxying configuration file, and, the Solaris Service Management Facility configuration file (which lets the accelerator boot mongrel when necessary.

  • apache_vhost.erb is the template for the Apache configuration file

  • smf_template.erb is the template for the SMF configuration file

To use, export the files from SVN to your config directory. So, inside your application’s home directory do

svn export config

Ensure you’ve got a working mongrel_cluster.yml configuration file, and if you haven’t already, create the capistrano deployment recipe cap –apply-to /my/rails/app

Then, add the following to the top of deploy.rb

require ‘config/accelerator_tasks’

and add two new properties (used to configure Apache for the new domain name)

set :server_name, “”set :server_alias, “”

See the Apache docs for more info about the ServerName and ServerAlias directives if you don’t know what they do.

Finally, change the restart task to use the new smf_restart task (which in turn calls the smf_start and smf_stop tasks):

task :restart do  smf_restartend

Once you’ve added everything to Subversion, you ought to be able to do cap setup to create the initial app directories, create your SMF configuration file, and, Apache 2.2 virtual host configuration file. The SMF configuration file goes into your application’s shared directory (that Capistrano creates). The Apache 2.2 configuration file goes to /opt/csw/apache2/etc/virtualhosts/myapp.conf.

Finally, try cap deploy to do a new release, and call restart which will try and start your Mongrel service. I’ve also created a svcs task that will show you all the services installed into the SMF. If your Mongrel instances don’t fire up, check the result by running svcs -x, or check out the /var/svc/log/network-mongrel-myapp-production:default.log and see whether there’s any info about why it didn’t start.


This is pretty rough and ready, but, it works for me with a stock Accelerator. However, this recipe does assume you are deploying your web and application servers to the same accelerator. It shouldn’t be tough to fix it up to figure out how to deploy to different accelerators, but I haven’t done it yet. Also, I’m still not overly familiar with Capistrano so if I’ve made some glaring mistakes in how things are done, also, please let me know (this is more of a first guess than anything, I’m hoping people will correct me).

I’ve posted something similar to the TextDrive forum, check out that thread in case people post follow-ups there too.

Most importantly, if people do use it and fix stuff up, please, please send the fixes back and I’ll get them committed into SVN for everyone.


DNS Hosting Recommendations Requested

Dear Lazyweb,

I am in the process of consolidating a lot of the various VPSes and hosting accounts I’ve accumulated over the years. I’ve had a great time with RimuHosting and would still absolutely recommend them to people, but, I ended up hosting most of my apps at my MediaTemple GridServer account, leaving my VPS at Rimu to just serve up SVN and some static stuff for friends.

One of the things I love about RimuHosting is they provide a great little DNS administration area, providing realtime-ish DNS updates. I can host as many domains as I like, and it’s nicely redundant with a couple of servers across their various datacenters.

I’m sticking with my $15 entry-level Joyent/TextDrive account for email (roll on the IronPort filtering!) and simple site hosting for friends. I’ve got a Small Accelerator for deploying other apps I’m working on, and, this blog.

I only have a handful of domains, but, I’d like to have a nice clean consolidated interface for managing it all, allowing easy updates and management.

EasyDNS is the obvious choice (to my mind). But, it’s a little more expensive (at $20 per domain per year) than I’m prepared to go for. It would work out to over $120 for the year!

So, what else is there? Anyone have any good recommendations?

Checking Object Equality In Mocha

I’m working on a little pet Rails project and wanted to use Mocha to isolate my controller tests a little from what is usually encouraged, especially in light of what happened last time. I figured I’d give Mocha a go.

I wanted to verify that my service was called with objects that look equal to what I was expecting. Ordinarily, it will compare instances - are they the same object. I didn’t want that, but rather wanted to test that the values of my (ActiveRecord) objects were the equal. Easy. Mocha allows with to be called with a block that is evaluated to compare the objects.

My tests look something like this

def test_should_ask_service_to_calculate_new_prices_for_booking  address = => "W1 1QE")  booking = create_booking  OrderBookingService.expects(:calculate_price).with(booking, address) do |b, a|    b.attributes == booking.attributes && a.attributes == address.attributes  end
  post :calculate_price, :booking => booking, :collection_address => addressend

It’s something I’ve had to do many times in the past with JMock and NMock - I want to test equality for an aspect of some other object but it’s always meant writing rather a lot of code. Neat.

I'm not so sure I LoveFilm

So here’s one for Marc McNeill.

I received a promotional offer from (one of the UK DVD rental companies) over Christmas and I figured I’d take advantage and give it a go again (I found I never used it last time).

Well, turns out I was wrong, I haven’t changed. I borrowed some DVDs of Lost (in the incorrect order I might add) and I’m yet to watch the episodes. Today I received another email with recommendations, prompting me that I needed to do this.

I logged into my account and found where I could cancel my account. I click the button to cancel and then see the following:

To confirm your cancellation please call us on 0800 091 1514.
A member of our Customer Services team is standing by waiting to speak to you they will be able to take you through the rest of the cancellation process as there are a couple of questions we need to ask you.

Why is it so complicated? What a sucky experience.

Running on the Joyent Accelerator

I finally received the connection details to my shiny new Solaris-based Joyent Accelerator over the weekend - apparently some hardware delays pushed things back a bit. Getting my Mephisto install running was pretty painless, here’s how I did it.

After logging in, I checked I had ruby

:~] admin$ ruby -vruby 1.8.5 (2006-12-25 patchlevel 12) [i386-solaris2.8]

Thinking I might have to install Ruby Gems, I checked that also:

~] admin$ gem -v0.9.2

Excellent, so no need to install anything there, brilliant.

The most stable setup I’ve had so far has consisted of running Apache and Mongrel. My preference is to run a couple of Mongrel instances proxied to from Apache. For that, we need mod_proxy_balancer and for that we need Apache 2.2

~] admin$ apachectl -vServer version: Apache/2.2.4 (Unix)Server built:   Feb 19 2007 00:18:52

So, to install Mongrel I did (following a little from TextDrive’s notes)

~] alias make=/opt/csw/bin/gmake~] alias install=/opt/csw/bin/ginstall~] sudo gem install mongrel~] sudo gem install mongrel_cluster

Sweet. So, all that remained was to get my existing database copied over using mysqldump, a quick rake db:migrate to bring my database schema up-to-date (so I can work with the latest Mephisto code) and all is well.

Finally, all that was left was to add a new virtual host configuration file for Apache. I used the sample that Joyent/TextDrive provided.

In total, it took me about 15/20 minutes this morning whilst eating breakfast. Pretty easy!