Coding the Game of Life

Over the weekend I attended the Global Day of Code Retreat. We held one at our offices in Aldgate, and welcomed 11 participants.⁰ We coded for about 45 minutes per session, and each session had a different constrain. The aim of the day was to practice writing code thoughtfully, driven by tests, and in small increments. The solution we were pursuing was software to run the Game of Life, a zero-player game that demonstrates emergent properties.

(That is to say that, like life among us human beings, it starts with a seed and sometimes grows, sometimes dies, sometimes stays the same but — here’s the kicker — it can’t be hurried. The only way to work out how a pattern will look at step 4,255, 903 is to go through all of those steps.

As in life, the only way to find out what’s going to happen is to wait)

We also deleted all of our code at the end of every session, which was freeing but also very frustrating. One particular example was when my partner and I had been working in two minute bursts, resetting to the last working point if we didn’t manage to make a passing test in those 120 seconds. That frustration and elation was definitely heightened when we then had to get rid of all that hard work.

I enjoyed it enormously, and I got a chance to talk about the work we do and evangelise about working with us.¹ In fact I enjoyed it so much that I went home and then came up with a solution to the problem solo, with commit messages that got weirder the later it got:

Read from the bottom up. They’re from my repo

It was a really interesting reminder of how I originally learned to code, which was by fruitlessly bashing at the keyboard like an unionised monkey in an infinite cage. I had no real clue what I was doing, and when things worked I got a huge rush of endorphins that spurred me on. Intensive sessions like these put me next to people who are in that space, who just want to get on and write code and not hang around waiting for this fuddy-duddy government bloke to explain what they already know.

I think I got a bit more senior without ever realising it.

I think that’s how it happens to everyone.

If you look over the commits, you’ll see a snapshot of what I was thinking at that point in time. I really prefer these long commit histories to ones that are artificially squashed and rewritten — at least as a learning tool. For example, my Cell class started as this:

class Cell:                                          
def __init__(self, alive: bool = False):
self.alive = alive
def die(self):
self.alive = False
def resurrect(self):
self.alive = True

and ended up as:

class Cell:
def __init__(self, alive: bool = False):
self.alive = alive

def black_or_white_square(self):
return u"u25A0" if self.alive else u"u25A1"

because along the way I realised the Cell class didn’t have to die. In fact, I could even reduce it entirely to a True or False value and never worry about creating objects at all.

Some people didn’t take this approach. Some had Cells that were very weighty and could calculate their own fate, reducing the need for a world and putting each cell in its own bubble. The huge value from events like these, in my opinion, is being exposed to quite different ways of thinking about a problem.

So now you’ve been exposed to mine. What do you think?

⁰ 24 signed up, so I’m curious to know how that drop-off rate compares to the average
¹ If you’ve got to this blog because you attended, you should check out the jobs we’ve got on offer and the skills we expect you to have as a junior data scientist or a junior software developer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s