red-green starts with red

Suppose I've written a test and got it passing...
@Test
public void yahtzee_full_house_scores_25() {
  assertEquals(25, 
    new YahtzeeScorer(4,4,3,4,3).fullHouse());
}
After refactoring I write my next test...
@Test
public void yahtzee_not_full_house_scores_0() {
  assertEquals(0, 
    new YahtzeeScorer(4,4,4,4,4).fullHouse());
}
And this passes first time. That is, it passes without failing first. One of the reasons for failing first is to be sure the test is actually running. For example, suppose I'd forgetten to write @Test and didn't notice that the JUnit output wasn't showing one more test passing. Ooops. A question I've been asked on several occasions is whether, in this situation, you should change the code or the tests to force an initial red. For example, my first version of the yahtzee_not_full_house_scores_0 could have been this, (where I've deliberately used 42 instead of 0 simply because 42 is a good example of a number that is not 0):
@Test
public void yahtzee_not_full_house_scores_0() {
  assertEquals(42, 
    new YahtzeeScorer(4,4,4,4,4).fullHouse());
}
I see it fail, and then change the 42 to 0 and see it pass. This works, and I have done this. Perhaps you have too. If so, do you agree that it doesn't feel right? I've learned that when something doesn't feel right my subconscious is trying to tell me something. I've learned that when I've got two choices it's often a good idea to look for a third. And there is a third way. I could instead start with this:
@Test
public void yahtzee_not_full_house_scores_0() {
  fail("RED-FIRST");
}
And when I've seen it fail, I delete the fail() and write the actual code I want to write:
@Test
public void yahtzee_not_full_house_scores_0() {
  assertEquals(0, 
    new YahtzeeScorer(4,4,4,4,4).fullHouse());
}
Or, as an alternative, I could start with this:
@Test
public void yahtzee_not_full_house_scores_0() {
  fail("RED-FIRST");
  assertEquals(0, 
    new YahtzeeScorer(4,4,4,4,4).fullHouse());
}
and when I've seen it fail I simply delete the fail() line.

Either way I get the mechanics of seeing the fail out of the way and then I write the code as a separate thing. By un-asking the question I avoid having to decide what to temporarily fiddle with - the code or the tests. I get to write the code I actually want to write. All the time.

yahtzee cyber-dojo refactoring




Several people have asked for refactoring sessions in cyber-dojo. The idea is that instead of starting from the minimal start code and working towards a solution, you start from finished (but poor) solution and work on refactoring instead. So here are four deliberately poor solutions to Yahtzee in Java, C#, C++, and Python just itching to be refactored! Just click the links and in the resulting page press the start-coding button!

when it shocked us

A while ago I set myself a goal of reading all four volumes of Jerry Weinberg's Quality Software Management twice. I'm 7/8 through and this morning some of volume 4, Anticipating Change, really spoke to me.

Figure 10-9 extends the simple view of a feedback controller, to show that the environment of each level contains both the levels above and below.
In a feedback control system, the roles of system and controller are symmetrical. It's only our perception that determines which is controller and which is controllee, which is high and which is low.
In all the cases I have examined, the error correction mechanism seems to start at the lowest possible level and slowly works its way higher. [Donald Norman. Psychology of Everyday Things].
Norman is talking about correcting errors in handling everyday things, like being unable to insert the car key, trying again, trying the key upside down, trying another key, wiggling the handle, trying another door, and finally realizing that it's the wrong car. But the same way of progressing through levels is commonly found in correcting organizational faults.
Maturity tends to mean reliability.
In terms of the Feedback Control Model, every one of the more than a hundred failures I've studied closely can be attributed to poor management.
Software is invisible only when we have not developed the correct engineering measurements. A hundred years ago electricity was considered invisible. We only knew of its existence when it shocked us.
Software often lacks sufficient stability to make meaningful measurements.


the cat in the hat

I've blogged before about how Patrick and I often watch The Princess Bride. Patrick has Asperger's syndrome and loves to watch the same film many times. Many many times. It would be easy for me to not watch a repeat-showing with Patrick on the grounds I'd find it boring. I think that not that many years ago that's exactly what I would have done. But something Jerry Weinberg wrote (in Quality Software Management volume 1 Systems Thinking, page 111) struck a chord with me. He said:

It's not the event that counts, it's your reaction to the event.

So now I challenge myself to watch the film with Patrick (for the umpteenth time) and change the way I react so I don't find it boring. For example, I can specifically look for scenes or lines that I can relate to software development. I've found there will always be some. Here are some from The Cat in The Hat:

For refactoring and continuous-improvement (the song at the end after they've tidied up the mess they made)

I've got to admit it's getting better.

For attitude (after they make the cupcakes which taste disgusting)

They're horrible. Who want's some?

For gratitude (again at the end)

This day has been amazing. Thank you.

For pair-programming! (when they're in the car)

Two people can't drive at the same time.

For testing! (when they're in the car again)

I think there's something wrong with your brakes. When was the last time you had them checked?

For quick and dirty (which is really slow-and-dirty)

There's no way to explain this to mom.

For QWAN, Quality Without A Name, when they're riding the Mrs KWAN roller-coaster:

Please keep your hands and feet in the KWAN at all times.

It's amazing how what you see changes when you change how you look.

big cyber-dojo in Beijing


Mike Long (@meekrosoft) ran a Cyber-Dojo for 32 people in Beijing yesterday. Way to go Mike :-)

cyber-dojo in the cloud

http://cyber-dojo.com is now properly hosted in the Amazon cloud :-) I'll leave the old server, 81.31.112.23 (in my house, under the stairs, with the flaky internet connection - I live in a rural area) up for a few days, but will be gone soon.

A few people have been asking if they could donate something towards running Cyber-Dojo. Now that I'm paying for the hosting that seems a sensible idea, so I've added a donate button. Thanks.

Emil's cyber-dojo




I ran a Mastering Agile Practice tutorial with Kevlin Henney at the recent Scandinavian Developer Conference in Sweden. Emil J├Ânsson attended and liked Cyber-Dojo so much he ran one at his company afterwards. He says:

Just wanted to let you now that the Cyber-Dojo session I organised at work last week went really well. We did the leap year kata in Java and we were eight in total, so we ended up working in four pairs. It was fun to hear all the interesting discussions taking place and it was perfect how we could jump between the different solutions of the pairs afterwards when talking about the code. The feedback after the dojo was all positive and my colleagues liked the Cyber-Dojo way of practicing.

I hope this will become a reoccurring event. Thanks for the excellent work creating the Cyber-Dojo.

It's my pleasure Emil.


ACCU conference charity bookstall



A big thank you to the excellent people attending the ACCU 2012 conference who raised £645.77 plus a €10 note plus a very small silver coin of unknown origin! This will be split equally between Paws with a Cause and The Autism Trust.

building a rails 3 turnkey cyber-dojo server




NOTE: The cyber-dojo github repo now uses ruby(2.1.3), Rails(4) and docker(1+).
I don't think these instructions will work anymore.
Instead see setting up your own cyber-dojo docker server

I've been working on building a cyber-dojo VirtualBox Turnkey image that uses rails 3 and ruby 1.9.3 on top of the Turnkey Rails app. I figured the steps involved might be useful for someone so here they are. You can also download them as a shell file here .

First I removed the existing ruby
# cd ~
# apt-get purge ruby-enterprise
Then install libyaml
# cd ~
# wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
# tar xzf yaml-0.1.4.tar.gz
# cd yaml-0.1.4
# ./configure
# make
# make install
Then install the version of Ruby I want (this takes quite a while)
# cd ~
# wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
# tar xzf ruby-1.9.3-p125.tar.gz
# cd ruby-1.9.3-p125
# ./configure --disable-install-doc
# make
# make install
Then pull the rails3 Cyber-Dojo source (hit return when it asks for a password). I got some utf-ascii conversion warnings which don't seem to matter. When asked if I wanted to overwrite an executable I responded [y]es. This too takes quite a while.
# cd /var/www
# git clone https://JonJagger@github.com/JonJagger/cyberdojo
# chown -R www-data cyberdojo
# chgrp -R www-data cyberdojo
# cd cyberdojo
# gem update --system
# gem update --no-rdoc
# gem install bundle --no-ri --no-rdoc
# bundle install
Then setup apache
# cd /etc/apache2/sites-enabled
# sed s/railsapp/cyberdojo/ <railsapp >cyberdojo
# rm railsapp
# cd /etc/apache2/sites-available
# sed s/railsapp/cyberdojo/ <railsapp >cyberdojo
# rm railsapp
# cd /etc/apache2/conf
# sed s/railsapp/cyberdojo/ <railsapp.conf >cyberdojo.conf
# rm railsapp.conf
Then setup passenger (it takes quite a while), and edit /etc/apache2/conf.d/passenger as directed by the output
# cd ~
# apt-get update
# apt-get install libcurl4-openssl-dev
# cd /var/www/cyberdojo
# gem install passenger --no-ri --no-rdoc
# passenger-install-apache2-module
Then
# cd /var/www/cyberdojo
# service apache2 restart
And viola, cyber-dojo was up. Saving to a .ova file creates a 418MB file. This will give you C and C++ (gcc 4.4.5), Perl (5.10.1), Python (2.6.6), Ruby (1.9.3). If you want to upgrade any of these or use any of the other languages you'll need to install their compilers and unit test frameworks.

cyber-dojo Skillsmatter podcast

I had the pleasure of running a Cyber-Dojo at Skillsmatter's 2 day Progressive Java tutorial last week. The session was video'd and is available here.