# Teaching Your Kids To Be Programmers

Programming 101 (image: desktopnexus.com)

I’m always keen to get my kids into video gaming, although I’m not sure why. Perhaps because of this, I was really taken by a story told by a friend (@Pixelh8) who reviews games on Game People with me. He tells of how a simple programming language (MIT’s Processing) and a little bit of Dad time, turned his kids into budding programmers. I thought you’d like to hear about it to0…

I like sharing my work projects with the kids and they are always more than inquisitive to find out what I am doing. After a long day out with mum, they wandered in to find me still working late on a complex program problem. Recently I’ve taken to using a MIT developed programming language called Processing to help explain things to these young curious minds.

A few minutes after staring at the screen one of my girls (7) started giggling and asked what I was doing. After reading the code she thought I was writing a very strange email to some one about these things called “x” and “y” and “rect.” I explained this was programming and it allowed me to control the computer. But of course more and more questions started coming out about what does “int,” “if” and “do” mean.

So I decided to open a new project to very simply explain what I was doing. Int means integer and that was a whole number and that we were going to give it a name called number. I said “imagine a box called number and that’s where we keep what number we are on.” The number automatically starts on zero unless told otherwise but it helps when explaining the code to have the number on screen for them to see.

`int number=0;`

I then went on to explain that programs work in loops by sometimes performing the same task again and again and that in this program to make a loop, one of the ways was to setup the draw function which simply loops what is inside of the parenthesis again and again.

`void draw(){   Loops stuff we put here! }`

I then said “Inside the loop I want the computer to tell me what number I was on, so I was going to ask it to print it to a screen, at which they laughed “you don’t print things on a screen, it’s not a printer”. So I put the following code in the loop.

`println(number);`

This printed the number we were on, on the screen again and again. We ran the program and again and again it “printed” the number 0 on the screen. The kids looked at me and said “but it’s not doing anything, just printing zeros”. They didn’t know it but they had already started learning the syntax. Just a couple of seconds ago, they argued you couldn’t print to the screen now they were annoyed it was doing it and referred to it as printing.

So I added another line of code inside the loop without telling them what it did.

`number=number+1;`

I asked them what they thought it would do, and after a few silly guesses I asked them “What number are we starting on?”, “Zero” they replied so I said it out aloud. “Number equals number plus one. It looks in the number box to find out what number we are on and adds one to it, so number is equal to zero and we add one to it what will it be?”

“One” they replied. “OK” I asked, “now that piece of code is in the loop, so it’s going to go around and come back to it, what will it do the next time?” “Two” they both replied.

So we ran the program and got 1,2,3,4,5,6,7,8 etc very fast shooting up the screen and made it hard to read the numbers. So I decided to add this.

`delay(50);`

This was simply explained as a way to slow the program down every time it got to that point, by 50ms. I explained that delay simply meant pause, “like when you are meant to be in bed, and every step you take on the stairs when going up to bed, you do it very slowly and delay getting to bed ” at which they giggled.

We ran it again and we could now read the numbers. I then added.

`if (number==50){println ("Woobaa");}`

I asked them what this might do? Ignoring everything they asked what Wooba would do, I said “It’s just a silly word you could put anything there”. “Will it make number equal 50 and print Wooba?” Which was amazing, we had only been programming for about fifteen minutes at that point. I explain that the double “==” isn’t going to change the number but ask it what it is. Again I said it out aloud “If number is equal to fifty do the things in these parenthesis, print Woobaa”.

We ran it and waited for it to count up to fifty, 47,48,49,50, Woobaa, 51, 52, we rain it several times because it was funny to them seeing computer speak utter nonsense. So we added.

`if (number==75){println ("Doobaa");}`

Which did the exact same thing except printed Doobaa when it got to 75. And finally we added.

`if (number==100){println ("Ooobaa"); number=0;}`

I asked them what this would do, and they got it first go. It would print Oooba when it got to on hundred. The only thing they didn’t get was when number was a zero again, what knock on effect this would have. So I talked them round the loop again, saying “now we are on zero, and we add one, we get one etc” and then “oh it will say Woobaa again!!!”

So we ran it again, 47,48,49,50,Wooba,….73,74,75,Dooba…98,99,100, Oooba and lots of giggles as a this serious computer was just saying silly words over and over again.

After that we just stopped programming, and I explained things like what if number started at 100 and counted down to zero, “it would be like the clock on Mario” they said. “Yes, and if you had another box called lives and that started on 3 and every time it reached zero it would take one away”, “oh yeah”.

“My goodness is that the time 9.10pm, we have been doing this for 45 minutes it really is time for bed now, you have successfully delayed getting to bed on time yet again” at which they giggled again and made their way to bed.

I sat there for a while afterwards and thought about the amount they had learned in such a small time, they had learnt about integers, variables, iteration and conditionals in forty five minutes, they had learnt to output a value to the screen and they understood it.

The computer was no longer another games machine or for sending emails. It was a giant calculator that could illustrate an answer with words or graphics.

The next morning one of them came to me with an idea for a program, she had been thinking about the idea for a while, but up until then it was just and idea that needed to be calculated. “Can we make something that works out the faster you drive, the more petrol you use, and fast whiz past the slow ones?” She had obviously heard about the idea probably on the kids news or one of the many science programs she likes to watch, but now she felt she could not only think about the problem but to do something about it.

The full program we entered is here. You’ll need a copy of Processing it’s free and very easy to set up.

```int number=0;
void draw(){
println(number);
number=number+1;
delay(50);
if (number==50){println ("Woobaa");}
if (number==75){println ("Doobaa");}
if (number==100){println ("Ooobaa"); number=0;}
}```