July 29, 2005

Haaarg, world!

Continuing the "Anthony's first program" series from last time.

When my six-year-old son Anthony asked me if he could program his own computer game, I was worried that he might be totally disappointed. It is not 1979 anymore. The gap between the primitive software you can put together in an afternoon and highly polished multimedia software you can buy at the store for $9.99 is huge.

In 2005, could programming hold the interest of a six-year-old at all? Does anybody even program their own computers anymore? And what tools would you use as a beginner? Which language? Which operating system?

I am a professional programmer, but the tools I use seem far out of reach of a beginner. I have no idea how a real novice should learn to program in 2005. And so after dinnertime last Friday, when Anthony asked me for the 10th time to help him write a computer game, we would have to come up with something. It was time to get started....

An Operating System for Vampires

For a six-year-old, the idea of writing a computer game was just like arts and crafts, costumes, and pretend. "Sam's sister wants to make a pet show game," Anthony explained to me, "the person who makes their pet do the best tricks wins." At six, you see no limits in the world. You can create anything you can imagine.

I had to explain to him that he would have to pick a simple game with rules. Making, for example, a "pet show" where you could tell your pet to do anything would be hard, because there were too many things you would have to teach the computer about pets.

So we had to pick something like "tic-tac-toe", or "guess a number from 1 to 100" or that kind of thing. Anthony decided "guess a number" would be a great video game, especially if a vampire was the one that was keeping the super-secret number. He would have to have a really scary vampire.

Anthony wanted to get started on his vampire game right away. He didn't have time to watch me fool with installing cygwin or python or the J2SE SDK. We had a couple hours. We would need to get something working before bedtime.

So before even choosing a language, I had to pick which computer to use: Windows or Mac. It really only took me a second to decide. On Windows, I would have to install a bunch of development tools - a language, an SDK, etc - and then I would have to get it all configured to actually work.

But the Mac is Unix. It is a hacker's system. It comes with all the important languages: C, Java, perl, and python, not to mention bash and sed and awk. And vi. And emacs. On the Mac, you can turn it on and go. We could get started right away.

"Vampire" would be written for the Mac.

Hello - er - "Haaarg," world!

So we opened up two OS X terminal windows and put them side by side. One window (running emacs) was for writing the program, and one window (with a shell) was for running it, I explained. I created a file called "GuessANumber", chmod 755, and then typed in an example program.

I picked the simplest, clearest language I could think of. Then I told Anthony, "this first line tells the computer what language we are using. It is called Python. In python, you can print things by saying print."

This is what I gave him:

#!/usr/bin/env python
print "Hello."

And I showed him how to run it:

> ./GuessANumber

Anthony is a typical 6-year-old, and he does not keep his opinions to himself. "That's no good!" He was disappointed. "The Vampire should say 'Haaarg, I've got the secret!' It needs to be scarier! Can you make it say that?"

But Anthony can type. Hunt-and-peck is something first graders know how to do in 2005. "Anthony, you can type it in if you like."

So here is what he did. He was especially happy with his own all-caps innovation:

#!/usr/bin/env python
print "HAAARG! I've got the secret"
print "it's a number.  1-100"

And then:

> ./GuessANumber
HAAARG! I've got the secret
it's a number.  1-100

His vampire had printed out HAAARG! A huge smile lit up Anthony's face.

We were off to the races.

Interacting With Python

I will spare you all the details, but I will show you a couple versions of the python program Anthony wrote. I find it interesting to see what a 6-year-old understands first, and what comes next.

Here was the first program that you could actually play:

#!/usr/bin/env python
secret_number = 28
print "HAAARG! I've got the secret"
print "it's a number.  1-100"
print "GUESS!"
guess = input()
if guess == secret_number:
  print "you win!"
  print "I WIN!"
> ./GuessANumber
HAAARG! I've got the secret
it's a number.  1-100

As soon as the program did this, Anthony said, "I want the game to be even harder! Let's make it one to a THOUSAND!"

"But Anthony," I said, "Even if you do that, I can always win your game by typing 28." He did not seem to be concerned about that at all. But then he changed his mind and decided that it was more important that the vampire needed to be better at taunting you.

Timing Is Everything

"I want it to wait two seconds before it says GUESS! Can we do that?"

The beauty of python is that it is a professional programming language, not just a plaything. The answer to 'can we do that?' is almost always 'yes', and 'it is well-documented and discussed on the internet.' Googling [python sleep] gave Anthony a beautifully small piece of code to copy, with just two more lines.

#!/usr/bin/env python
import time
secret_number = 28
print "HAAARG! I've got the secret"
print "it's a number.  1-100"
print "GUESS!"
guess = input()
if guess == secret_number:
  print "you win!"
  print "I WIN!"

As we watched and waited two seconds for "GUESS!" to show up, Anthony's face lit up again. "GUESS!" he exclaimed, in his best Scary Vampire voice. And then he laughed. And then back to programming. "It should wait a little longer! Maybe seven seconds," as he started typing into emacs again.

Timing is everything.

To be continued

The next step, of course, was to teach Anthony how to make a "while" loop so that you could guess a few times. And then after that it took a little cajoling to convince him that the gameplay would be improved if you gave hints like "try a bigger number" or "try a smaller number". Somehow we got through it all.

Before the end of the evening, we had a classic "Guess My Number" game running. The two hours between dinnertime and bedtime had just barely been enough to get it written and working. We showed it off to Mom, who was suitably impressed, and then got into PJs and tucked into bed.

In the next article, I will show you the code, and then tell you what happened the next morning.

Posted by David at July 29, 2005 05:53 AM

We're hiring.

Let me know when he learns Java.

Peace. ;-)

Posted by: Cameron at July 29, 2005 09:35 AM

I wish my dad would have been like that. Great story!

Posted by: Michael at July 29, 2005 02:37 PM

I was about seven when I used the internet to teach myself QBasic on an old Compaq desktop. My dad gave me the computer and the freedom to learn how to use it. It wasn't long before I wanted to do more than just play other people's games. I totally understand your son's ambition, and I really appreciate what you're doing for him.

Posted by: Clay at July 29, 2005 02:50 PM

I hope i have kids like that one day!!!
Although i cant code....Damn.
So when ure son wants to teach me how to write python send him round!


Posted by: NOGG3R5 at July 29, 2005 03:09 PM

this anthony has to be just about the smartest kid in the whole wide world.

love, Grandpa Paul

Posted by: paul bau at July 29, 2005 04:02 PM

Ah... you should start his own blog... "As my childs game development continues..." it'd be fun to watch him progress and make more games.

Posted by: Marble at July 29, 2005 07:01 PM

Awwww... That's sooooo cute! Makes me want to have kids!! :)

Posted by: dJsLiM at July 29, 2005 10:21 PM

All my dad did was teach me fortran. :(

Posted by: Stupidideas at July 30, 2005 08:08 AM

RE: Cameron

That's a vampire programming language...it sucks.
Pythons only make me laugh.

Posted by: LIM at August 1, 2005 09:42 AM


now teach the kid how sed works...

Posted by: LIM at August 1, 2005 09:53 AM

This is fantastic. Cheers on the good work

Posted by: harsh at August 2, 2005 10:11 AM

hehe, the vampire with the number reminds me of my childhood with sesame street and "Graf Zahl" (in german, count count in english?;)

Posted by: z0rz0r at August 2, 2005 11:59 AM

Great story! Our son is 14 months old right now, and I've been looking forward to starting him on progamming. I had decided on python as a good starter language, too.

Posted by: David W. at August 2, 2005 08:46 PM

That's great. Brings back memories. Long before my teens I got a "Commodore VIC20" and a book of BASIC games. I learned a lot having to type in my own games.

Posted by: Dan at August 3, 2005 05:55 AM

Great story! My son wrote his first program, with my help, in a similar way. I think he was about 10 at the time. We used Visual Basic. It was a fortune teller game (like that game that you make out of a folded piece of paper).

Now he is 22 and designs computer chips for a living.

Posted by: Pat at August 3, 2005 02:28 PM

My son is the same age and asked the same question. I found that Gamemaker at http://www.gamemaker.nl was really great for that age. Free trial, and a value for money full version. Windows only, though. Written by Mark Overmars, a Dutch CS professor.

It has good tutorials and a nice range of example games, you can upload your own little sprites of the his favourite characters, and you can debug why things don't work as expected. We started with a simple bouncing sprite game.

Gamemaker is to games what programming Lego Mindstorms is to robots.


p.s. I'm just a happy user, not affiliated with it in any way.

Posted by: Matt Doar at August 25, 2005 06:05 PM

makes me want to have a kid so i can do this too.

now, to find a wife..

Posted by: ramil at October 27, 2005 04:25 AM

I too support Gamemaker www.gamemaker.nl Your 6 year old is now 7 and thats old enough
see kids work at http://online.haileybury.vic.edu.au/sites/edrington
resources at:
www. freewebs .com/schoolgamemaker

Posted by: Tony Forster at March 24, 2006 05:54 AM

OH~My GOD, I haven't heard of Computer when I was 6 year old!So it's the reason that I'm not a progammer.?

Posted by: 太阳黑子 at May 9, 2006 07:11 AM


I would like to include video game creation in my summer program. The age group is 14+. Is there software you can suggest that i can use. My comptrs are IBMs.

Posted by: Aminah at May 21, 2006 03:42 AM

Great story. Ned Betchelder (http://www.nedbatchelder.com/blog/200605.html#e20060525T082953) posted a link to this on his blog in response to an e-mail I wrote him, thanking him for his own stories of this nature and announcing that I am now the father of an awesome little two-week old son. The prospect of sharing my hobbies, as I did with my father, excites me, and I just love stories like this.

Posted by: Calvin Spealman at May 25, 2006 12:07 PM

I know Anthony's Grandpa Paul and he is always bragging about Anthony's brilliance. Way to go, Anthony!!

Posted by: Connie at May 25, 2006 02:44 PM

Great story, but I am afraid that I will have to report this to child welfare.

Making kids use EMACS is considered abuse is most civilised countries!

Posted by: port7 at May 26, 2006 06:48 AM

I hope i have kids like that one day!!!
Although i cant code....Damn.
So when ure son wants to teach me how to write python send him round!

Posted by: adam smith at April 14, 2007 09:57 AM

makes me want to have a kid so i can do this too.


Posted by: George Sorof at April 19, 2007 12:16 PM

We were talking about you and your family this morning Anthony. That's when I learned that you are a programmer. I'm not surprised. I knew you when you were a baby. Your Grandpa Paul was telling us then how smart you were! He was right. Keep up the good work. And thanks again for helping your Dad fix my husband's computer one afternoon so long ago. Love to you and your family.

Posted by: Sandy Drayer at July 24, 2007 04:17 PM

I like the teaching of his dad and I hope Anthony did understand the mechnics of it

Posted by: jerome at August 13, 2007 03:52 AM

Cool! I'm 11 years old, using Ubuntu Linux(yeah, I use N00buntu, so deal with it!), and I have written my first program(Python) too! On Christmas/Winter vacation, my brother seemed to get an idea to create a video-game also. I'm sort of not sure how I will be able to help him, because I am just starting, and I don't know how to tell him that you can't just imagine all these details (like walking, or very (hard) fancy graphics). I guess if he can get far enough to listen to me when I explain things to him and not say "that's stupid!" or something similar, that he will understand what I am talking about when I say 'PLEASE JUST KEEP THE GRAPHICS SIMPLE!' and remember 'function first'. Anyway, I think you got him off to a good start. I wish him luck!

--Caleb Herbert

Posted by: Caleb at January 5, 2008 01:50 AM

Thanks, my eight-year-old and I just wrote our first python program together, based on your guessing game. He thought it was pretty fun to keep adding more features to it (e.g. a for loop for multiple guesses, and a "too high/low" hint. I can see that the if/then logic is a little beyond his current capabilities, but he was able to figure out bits and pieces of the program with some help.

Posted by: Mike Bridge at April 29, 2013 05:04 PM
Post a comment

Remember personal info?