Monday, September 07, 2009

Teaching Kids To Read Programs

Today I taught my 8 year old son Jacy how to read some simple programs. I've been taking my time in picking what to teach him next about programming because I don't want to push him too hard. He get's frustrated sometimes and I have to be inventive in my teaching styles. I had an idea a few weeks back about a Simon Says related game that I thought would work, and tried it out today.

The concept is quite simple, write out a simple if/else if/else statement centered around some particular value, have him read it, then say "Simon Says 'value is something'". Here's a very, very simple example. I write down this program and have him read it:

if x is 7 then jump
else sit down

Then I say, "Simon Says x is 5!", and he would know to sit down.

This worked, but as soon as I tried some more complicated programs he lost interest almost immediately. I don't give up easily though (or ever), and so I quickly came up with a new plan.

He complained that he didn't understand, and I think the x was throwing him off just a little bit (even though I think he understood it, and he certainly did later on). So, I decided to use crayons instead, since they are more concrete. Also, I decided to make it a bit more fun by adding pretending to the mix. I started over with the following program:

if color is red then PICK NOSE
else PUKE

Of course, all boys like to pretend to pick their nose and puke. This program was much more fun to him and he was much more willing to read it. Like I said, I'm sure he understood the first programs just fine, but it has to be fun.

Now, instead of saying "Simon Says Color is Red!", I had a box of crayons, and I'd simply pull a crayon out of the box. Less abstract, more concrete, more visible, more involved, more fun. This worked like a charm as he quickly pretended to pick his nose.

Now that I had his full attention I was easily able to add in an else if statement that I had failed on earlier:

if color is red then PICK NOSE
else if color is black then DIE
else PUKE

This was easy for him. I'd pull a red crayon out of the box and he'd pretend to pick his nose. I'd pull a yellow crayon out and he'd realized the first two don't match, and he'd pretend to puke. I'd pull a black crayon out and he'd pretend to die. No big deal, but still very cool.

Now I was able to add in some more interesting boolean logic:

if color is red or yellow then PICK NOSE
else if color is black or blue then DIE
else PUKE

This was also very trivial to him, as I expect anyone would imagine. But, I think all of this was necessary to get him back to the abstract forms that I started with. Now that I had the fun element, and the else ifs, I was able to go back to a program similar to the one I first failed on.

if x is 7 then PICK NOSE
else if x * 10 is 20 then DIE x times
else PUKE

This one is a lot more complicated than the any of the previous programs, but I felt that he did get it right from the start, he just needed the right encouragement (puking, picking, and dying, of course). Sure enough, he was ready for it. I said, "Simon Says 'x is 2'", and he pretended to die 2 times. He really did understand what x meant. However, I could see how some of this was a leap, and suggest progressing slower if needed. Here are some examples:

if x is 7 then PICK NOSE
else if x is 5 then DIE 5 times
else PUKE

followed by:

if x is 7 then PICK NOSE
else if x is 5 then DIE x times
else PUKE

then maybe something simpler than multiplication:

if x is 7 then PICK NOSE
else if x + 1 is 3 then DIE x times
else PUKE

There's a ton of room to be very creative here, and anyone can go at their very own pace, and each step can be broken down very slowly. This is all very exciting. My son is reading simple code! It won't be long at all before he's writing it. But, certainly it will be great to have him master reading it first. We do much more reading of code than writing as software pro's, and it's a skill that far too many students never learn. :(

What's next? I'm not sure. Probably nested expressions. I think I could do that by introducing two colors like so:

if first color is red then
if second color is blue then PICK NOSE
else if first color is black or blue then DIE
else PUKE

Those of course could get far more complex.

A few final notes to those who actually intend to try this with their kids.

  1. He was very particular about having solid lines separating the if part from the else if parts, and the else parts. This helped him read the program a lot more clearly. I think a good deal of space would have done just as good. My initial programs were a bit bunched up, and he didn't like that at all.
  2. He didn't really feel comfortable reading the program out loud to me. He would read it, and I knew he understood it, but if I asked him to read it out loud he got mad.
  3. Along the same lines, if I asked him to explain how he got his answer he didn't want to tell me. I'd have to point to parts of the program and ask him if that's where he was, but it just didn't go very well at all. He knew the answers, just didn't like talking about it. Help understanding this phenomenon would be appreciated.

Please let me know what you think!


  1. For number 3 of the final notes, I would call this similar to the "What'd he say?" during a movie. You heard it, you understood it, you even got the concept, but there's no way you could repeat it, simply because someone asked. I would instead work on having him explain parts of the program, not necessarily asking how he got the answer, etc. You could have him step through a series after you're done (such as "What'd we just do? Why did you puke?"), leading him through the logical though process.

    By the way, all you need to do is throw a "while dad pulls a crayon out of the box" at the top and you have taught him about while loops, which is a small step from foreach loops (foreach crayon in the box...) which can be similarly abstracted out to for loops.

  2. A very interesting approach. I have a 9 year old son myself who asks me to teach him program.
    (What is much heavier as we are Germans, so the 'if' does not match the spoken term naturally)

    I started things like that once with one of my elder sons, and used the 'println' statement too. Was exciting for him to see that the computer does what he commands ("but it's too stupid to know what you mean by 'bring cacao', son...")

    I would indeed try to create a library that we can use in a command line shell, which provides simple and funny vocabulary, so that the computer indeed reacts to his orders.

    Reg. your 3rd note: At this age, differences in mental conditions (hope that word's right) are very broad. It much depends on the individual child, how he approaches the problem and the solution. So I expect the WAY of solving the problem to be a subconscious act. The solution is clear, the way to it, the WHY, not. This kind of mathematical reasoning will typically evolve more and more when growing up. In younger brains solution much more 'happens'.

  3. Hi, the second 'Anonymous' again :-) :

    Here's a nice link explaining the child's way to think.

    This is where an 8 year child comes from:
    and here, where it goes:
    http: //

  4. I've been surreptitiously preparing my 5-year old for programming...

    * built him his own computer that he is responsible for patching and securing
    * taught him number systems after he learned to count (he can do base-2 now)
    * taught him to type - Mavis Beacon (~10wpm)
    * taught him logic - explaining every day things to him
    * got him addicted to legos...

    The actual programming will begin this holiday. I've bought him the Lego Mindstorm kit. This thing looks awesome! You can build all sorts of different robots and can program the robot using a gui to do various things. The robot has arms and can distinguish colors. I'm not sure who will have more fun with it...

  5. Excellent. Hope things are settling in well for you and Jacy.

    As you work out the kinks, maybe start teaching a computer science for kids summer course.

  6. Hello Jack.

    After reading your posts, I would like to inform you of a programming teaching and learning tool I have been developing called WizBang.

    It's free and open source. It's available on sourceforge at:

    One of the great features of WizBang is that you can build and run programs visually. But when the time is right, the programs will compile to C++ or Python so the student can actually start learning a real language AFTER learning programming concepts.

    I would be thrilled if you could try it out with Jacy and give me any feedback! Don't forget to download the examples from sourceforge, too.

  7. This site/article is about providing you all the information you need to evaluate boschdishwashers.