Processing bedtime: a new breed of script kiddies

I like sharing my work projects with the kids and they are always more than inquisitive to find out what I'm 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 (aged 7) started giggling and asked what I was doing. After reading the code she thought I was writing a very strange email to someone about things called x and y and rect. I explained this was programming and it allowed me to control the computer. Then, 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 explain in simple terms 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 at 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 set up the draw function which simply loops what is inside of the brackets 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". Moving on, 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?" They replied, "Zero," 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 shooting up the screen very fast, which 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 50 milliseconds. 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. "Will it make number equal 50 and print Wooba?" they replied, which was amazing given that we had only been programming for about 15 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 loud "If number is equal to 50 do the things in these parenthesis, print Woobaa".

We ran it and waited: 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 I asked 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 three and every time it reached zero it would take one away."

And then: "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, conditionals and how to output a value to the screen. 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 an 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 programmes 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, but it's free and very easy to set up.