Can you teach me how to make computer games?

February 4 2010

I was asked recently by a friend to teach his son — we’ll call him Marcus — how to program. Like many children (and many to follow) Marcus just wanted to make games. In this instance, I thought of Python and the PyGame library for it’s breadth and quality of documentation. Sadly, I still needed to teach him the basics of programming and Python isn’t as forgiving to beginners as I’d like.

My challenge was trying to keep things fun, while still learning how to program. Over the years I’ve read numerous technical books, but none compare to the accessibility of Why’s (poignant) Guide to Ruby when it comes to understanding the mindset of a language. The bonus of this would be that a lot of the knowledge learnt would be transferable to Python as well.

Learning to program was a secondary aim

When I learn a new programming language I tend to read a book or a set of tutorials end-to-end, completing every exercise and example until I understand it. In comparison, the poignant guide reads like a story rather than sticking to technical examples. You’re taken through different landscapes with bacon-craving foxes, granny bombers and floating whales. While you’re laughing at chunky bacon jokes you’ve already learnt the basics of instance variables, class methods and method arguments. The beauty of the poignant guide starts to shine through when you see the beautiful comics. At first they seem messy, but the style adds to the stories making for a much more compelling learning experience.

As a side not, while I find the comics endearing I can understand why many programmers would be put off. If you’d like to get started with Ruby quickly and are confident in your core computer science knowledge this might not be the book for you, but if you’re a beginner or are about to teach someone the basics this might be a great choice. As an alternative, you might be better off trying the pick-axe book for Ruby.

Hello World!

We both breezed through the poignant guide within a day, allowing enough time (another day) for me to try and apply some of the knowledge to Ruby and gaming. We both sat down and started to build a basic text adventure game and began by typing out some of the common features of the game. It’s a puzzle game where a player moves through different rooms fighting demons by farting on them. I initially spent an hour building out the classes for each of the objects in the game explaining why this is useful, after which we switched seats and I helped with any unknowns. Some of the programmers out there might call this pair programming.

Marcus was a great student and was able to get the game finished in less time than I expected. Probably the most enjoyable part of using the poignant guide to teach programming was that I didn’t have to state “use an array” and get a confused look back. Instead I would refer to the different components as they were laid out in the stories, such as caterpillars (arrays) and loud words (destructive methods).

Where do we go from here?

It looks like I’ll be heading back next weekend to add to the core Ruby knowledge. My aim is for Marcus to be using Python and PyGame by March and I’ll start teaching some simple habits to make the switch as smooth as possible — whitespace is probably going to be the first of these.

If you’re ever asked to teach someone how to program I can’t emphasise enough how useful the poignant guide will prove to be. In addition, using Ruby meant that the usual traps that most new programmers fall into — forgetting semi-colons, curly braces and brackets — never see the light of the day.

If possible, I’ll try to follow this blog post up and track Marcus’s progress. Should he also consent I might put some of the source code up should you wish to get a better idea of how a text adventure game could be laid out in Ruby. Chunky Bacon!