in Coding, NaBloPoMo2019

NaBloPoMo #16

I’m going to do a quick review of a piece of code with 12 commits. It implements a fairly basic example of the Game of Life. Reading the rules of that game will be helpful if you haven’t read them yet.

In this blog, I’m going to try to guess what each commit does. Tomorrow we’ll compare and learn a valuable lesson about writing good commit messages.

commit 5bf9e330b02a6bc8122cce22f4f8c8a9be504228
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date:   Sat Nov 17 20:26:21 2018 +0000
Creates grid in correct size

I mean this seems clear enough. I’m guessing there’s a function to create a grid with a size?


commit 21082b9bf56673072159cda9b4f32527188aff37
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 21:10:34 2018 +0000
Takes care of (literal) corner cases

Oh man I’m already unsure. I know in the Game of Life we have to deal with corners slightly differently. If you’ve made the grid as a 2-D array and try to count to the left of the left hand side, for example, you’ll get an IndexError. So that’s my guess? But I don’t seem to have implemented any kid of solution to non-corner cases yet.


commit 50a4fb5c20d232f4653d29ad1e84d1fb2edb83de
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 21:26:23 2018 +0000
Refactored to pull out neighbour objects immediately

I have absolutely no idea what this does


commit c14f349f068b7954f8fa8cd3bb815aa9cceb6440
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 21:40:05 2018 +0000
Cells die and can be brought back

Okay, that’s much better. In the GoL, there are some rules that define whether the state of a cell in the grid can change. We like to call these alive and dead because it’s the Game of Life, but I’ve probably just set these as True or False values in the grid. In any case at this point I guess I’ve implemented some mechanism to kill/resurrect the cells.


commit a0b54baca0c59fd4154a783d04fb4fbd8f3052fc
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 22:04:03 2018 +0000
Grid can determine the fate of a cell, given its neighbours and its state

Ah nice! So it looks like I’ve implemented a method that takes a cell (and apparently all its neighbours? What were you doing past Jonathan?) and its current state and works out if it lives or dies in the next iteration. So I must have implemented all the rules, I guess?


commit 879993c339f074e972ee2f10de0693ee7ab724c9
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 22:19:41 2018 +0000
The Grid knows your fate!

Deep sigh.
Don’t code past ten folks, apparently your brain turns into a blizzard of nonsense


commit 8868a838f771bdf8193708c4daf7909e22a38c2b
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 22:43:26 2018 +0000
The Grid knows the fate of all!

Oh for goodness sake. At a guess maybe there’s now a method on the Grid class that works out the state in the next iteration for every cell?


commit 7383b5a68a21286d580f2a1d4cf5ea5fc40dcd2b
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 22:46:15 2018 +0000
Removed the cell

I don't think the cell needs anything more than to hold its state. I may get rid of the object later and work on pure booleans

Oh okay, so apparently I had a Cell class. Except the title is Removed the cell while the body seems to suggest I’ve not got rid of it. For goodness sake


commit 124d2d84a9900a6efae2a223d595a15df8a34e2b
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 23:04:37 2018 +0000
The Grid now accepts an inital state

As what, a tuple? An array? What on earth does that mean?!


commit 7916a9278487226002b9708104c5da3dd65341e2
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sat Nov 17 23:21:12 2018 +0000
The world ticks. The grid is remade. Dooooooom

And apparently after 11pm you lose any vestige of normalcy.


commit 9f1239ea981f57ce9bc89a008a037b9ce36479e8
Author: Jonathan Kerr jonathandrewkerr@gmail.com
Date: Sun Nov 18 08:16:15 2018 +0000
Completes Game of Life

This commit completes the game of life. Potential extensions are passing in command-line arguments for the initial state

And, in the morning, a bright message that says everything is finished without any reference to last night’s weirdness. Perfect.


If you’d like to get a headstart on me, the code is publicly available. I’m going to reflect on how much better I’ve got as a developer in the 12 months since I wrote this.


November is National Blog Posting Month, or NaBloPoMo. I’ll be endeavouring to write one blog post per day in the month of November 2019 – some short and sweet, others long and boring.

Write a Comment

Comment