Archive for the ‘katas’ Category

Driving out feature ambiguity

Friday, January 15th, 2010

Cucumber features are very useful. The ability to spec out what the customer wants in detail in a format they can read and understand really helps to communicatate what needs to be done. This combined with the ability to execute the feature to ensure that it is completed correctly catches many bugs and incorrect assumptions.

However there is one area of bugs that features don’t catch so well, and even cause to some extent. These bugs are built right into the text in the form of ambiguity, sometimes through the constraint of features being executable.

This came up recently in a conversation with James and Enrique at Eden Development about James’ apprentice task, the Snakes and Ladders Kata. It turns out that the text of one of the features runs against the commonly understood way that Snakes and Ladders works:

Scenario: Win the game
    Given player 1 is on position 97
    And player 1 rolls 3
    Then player 1 has won the game

Question: is that a valid scenario? Given the commonly understand rules of Snakes and Ladders, you cannot just start on position 97. Implementing it as written complicates the domain model.

How do you implement the first step? Do you go for a simple:

Given /^player (.*?) is on position (.*?)$/ do |player, position|
  @game.set_player_position(player, position)
end

The potential issue with this is that you are exposing a method that in real life won’t get called, just to set up a test. It’s also tying your model down to a particular structure, by implying that the game stores an arbitraty position variable for a player. This might not be the best way to model the problem.

The other option is to change the scenario such that the “Win the game” is tested in a similar way to the following:

Scenario: Win the game
    Given a game is started with two players
    And the following dice are rolled:
      |3|
      |4|
      |5|
      |5|
      (etc.)
    Then player 1 has won the game

That satisfies our understand of Snakes and Ladders, and gives us more freedom in our domain model. In this case, we simply modify the agreed scenario in the code and sidestep the problem.

Right? Wrong.

The important thing to remember is that the customer is always right about how the software should behave, even when it violates our commonly understood assumptions about the world. The software they want you to build might require a different implementation of Snakes and Ladders. They might have a 3 year-old daughter they’re planning to play the game with, who always wants to be given a headstart. In this case, we’ve not delivered what they want, simply because it makes life easier for us. We’ve let our assumptions and our concerns for good design drive out the features, rather than letting the features drive our design.

There’s another possibility: when the customer wrote this scenario, they simply used “starts on position X” as a shortcut and don’t really care if it’s possible to do this in real life. In this case, we can work with them to write the scenario so as not to cheapen our design for the sake of easier feature writing.

The key insight: there’s no way that we can know which it is from reading the scenario. We have to ask the customer and drive out the ambiguity in the feature.

We mustn’t let the necessary constraints of executable features build ambiguity into your conversations about what the customer really wants. And we must be constantly talking to the customer all the way through the iteration, especially if they’re not on site.

You might think “It’s only Snakes and Ladders, what does it matter?” It matters a great deal: situations like this come up regularly in real life projects. Practising how to deal with these issues and the conversations that result is one of the many powerful things you gain by doing katas.

What’s your take on the above problem? Have you come across it in real life?

Snakes and Ladders Kata

Sunday, December 20th, 2009

I’ve been mentoring a couple of guys at Eden over the last few weeks. They’ve been working away on the Binary Chop kata and it’s been generating some interesting discussions on what Test Driven Development actually is, and how to do it properly.

More on that in another post; today I want to outline the next task I’ve got prepared. Continuing on with the TDD theme, I’ve prepared a basic specification of Snakes and Ladders, using Cucumber features to give a simple outline.

The task is to take this basic github repository and prepare a kata which fully implements the features given using TDD.

If you’d like to try it yourself, feel free! Any patches to the features would be most welcome. Let me know how you get on.

UPDATE: I’ve fixed a bug in the features (thanks nickh) and merged in a patch from ohthatjames to provide some basic support files.

UPDATE: Olly Legg commited a couple of tweaks and improvements.

Practice makes perfect

Wednesday, October 21st, 2009

I have recently been struck with the idea of practising coding skills. It makes so much sense. In this video, Corey Haines talks about the necessity of practice, and likens it to learning a guitar. You don’t just play a song right through first time, and then move on to another. You need to spend time practising the chords, and changing between them.

Road Thoughts – Practice from Corey Haines on Vimeo

In the same way, as programmers we need to sharpen our skills by doing little practices (sometimes called katas from the Japanese word 型 meaning ‘form’) and repeating them over and over until we get them just right. The skills we learn during practice will be ready to use when we need them in a real project.

The atmosphere at Eden has changed recently as people are taking it upon themselves to learn new skills and practise katas. Suddenly we’re all looking at each other and thinking “I don’t want to be left behind!”. Just as Uncle Bob said yesterday:

You raise the level of professionalism in your company by raising yourself. Refuse to stay where everyone else is.

- @unclebobmartin

That said, i still find it very hard to motivate myself into actually doing some practising! There’s always so much ELSE to do, right?! I love the idea, but i need a bit of a push getting started. I need a mentor to guide me.

I have forked coreyhaines / practice_game_of_life on github and got as far as running the cucumber specs. At the moment i’m not really sure what to do next but i’m mulling it over and will hopefully make a start on coding something this week. I’ll probably completely mess it up a few times and have to start again, but hey, i’ll learn a lot from it! That’s the whole point of practising, isn’t it!

I will update here to let you know how i get on! :)