Game of life

I never expected to find myself saying that solving Game of Life (GoL) was easiest thing I have done so far. I do remember feeling ease and lightness while writing it, I don't know whether I was in the flow while doing it, but it is very clear to me that TDD took me there!

I first got introduced to the problem at the Global Day of Coderetreat event, which was organised by my company last year, although I wasn't yet working for them at a time. The purpose of the event is to be mindful about the code you write, about taking different approaches, about pair programming and about test driving it as you meant it. You do it in very short sprints of 45 minutes, after each sprint you discard (completely discard!) your code and pair with someone you haven't yet paired that day, so each sprint you start completely fresh.

The goal is not to complete the Game of Life on the day, plus you are not really given the time. So not having solved it, left me under impression that it is super complex. I did tell myself I will come back to it and shelved it for time being.

When I was given it as a task the other week, I felt very intimidated before starting. My first go at it lasted half an hour and I didn't like the direction I was going in. So I chucked the code and started over. Wrote a simple test and little by little solved it! It was an amazing feeling, a breakthrough kind of feeling, may be I am finally getting TDD?!

I still don't always know where to start but I now have the confidence that I will be able to solve pretty much anything if I rely on TDD.

Trick is in granularity of tests, I have mentioned before that Kent Beck says that you don't always have to move in tiny steps, only if you really have no idea, then TDD allows you to control where you can take your code. It helps you to see the various paths and you become much more aware which paths you have been down and which you are yet to explore.

I am not quite done with GoL, you can never really be done with it. According to a lot of exprerienced programmers, the domain of the problem is such that it can educate us every time we tackle it. I am to read Corey Haines' paper on simple rules of design and he used GoL to communicate his point. Really looking forward to the paper and and to seeing different examples of other approaches, to the one I took.

My mentor actually liked quite a few aspects of my solution, which is a big win for me after being lost in the solution for Mastermind for some time.

If of interest, my solution is up on Github. No promises, but it may be useful, if you want to see the commit history and trace how I evolved my code. May be it will help you discover something about the GoL, or the TDD, at the very least you will just get to observe my train of thought. Actually the worst case that neither of things mentioned will take place, so may be don't look at it, please don't look at it.