15 Years!

Learning a New Programming Language (aka writing Simon)

Guest post by Alan Rogers, volunteer on the OGPC planning team.

Whenever I need or want to learn a new programming language, I like to do it by writing a Simon game. Most people are probably familiar with Simon. It’s a very simple game, but involves a little bit of everything required to create any other program. It has graphics, sound, random numbers, loops, a user interface, complex data structures, etc.

If you don’t know Simon, it works like this: the computer highlights one of four buttons and plays a sound, then the player repeats what the computer just played. Each iteration adds a new button. The object of the game is to remember as large a sequence as possible and replay it.
I’ve written a Simon game in at least six different languages for almost as many different operating systems. No matter what language used, the basic game algorithm is the same and goes something like this:

  1. Computer selects a random number between 1 and 4
  2. Store the result in an array or list
  3. ‘Turn on’ the selected graphic and play a sound for each array entry
  4. Wait for user input
  5. Compare user input to storage
  6. Repeat or Die

It’s easy to become familiar with the syntax and style of any new language because I’m doing something I’ve done half a dozen times before. I know what functions, user interface objects, and data structures I need to create.

The basic functions for Simon are built into almost every language, I just have to figure out what they’re called and how to put them together using a different syntax or structure. For example, writing this in Flash and Actionscript is very different from creating something similar using iOS or Java.

It’s the familiarity that helps me. I already know what the bits of code for this game looks like in several different languages, now I just have to figure out how my old functions are created in the new language.

Take number 2 for example: ‘Store the result in an array or list’ … creating an array or list is usually a simple function, common to all programming languages, and even drag-and-drop interfaces, but it is implemented differently. It forces me to learn some things about the new language: Does the array index begin with 1 or 0? How do I create the array? Do I have to prefill it, do I give it a maximum size, does it expand automatically as needed? These are things I have to figure out to make it work.

Then, after storing the result, how do I read and compare it to the user input? How do I get that user input?

What about number 3 above: “Turn on” the graphic and play a sound. Can I create graphics and sounds using the language tools, or do I have to create something externally? How does the program know where to find them? Do they get compiled together, or do they have to exist in a certain directory path?

In the end, by doing something familiar, that I have done many times before, I’ve learned quite a bit about my new environment.

I hope you find some useful ideas from this post and use the knowledge you already have to explore new possibilities.

And yes, for what it’s worth … I’m currently trying to figure out how the Apple Xcode interface works and create a Simon for my iPhone.

Leave a Reply

Your email address will not be published. Required fields are marked *