Reading, Writing and Random Access Memory
There are certain important life skills that parents are obligated to instill upon their children. It's our responsibility to make sure that our kids have a have well developed I/O skills, a strong moral backbone, a social conscience and, most importantly, that they know how to program.
My 5 year old girl recently started inquiring about what I do for a living. More specifically, she wanted me to show her what I did all day and explain how I did it. Now, this would have been really easy if I was a bricklayer, as we have plenty of Bob the Builder DVDs lying around the house that I could have shown her. However, I'm not. I develop line of business applications for a living. So what exactly can you teach a 5 year old about programming, and how would you go about it?
Obviously I needed to start running through Charles Petzold's seminal book, Programming Windows, with her. The Windows Message Pump is an essential concept that all 5 year olds have to know. Or maybe not.
I decided to simply explain a few fundamental concepts that would enable her to "think like a programmer". I didn't want to push anything onto her, and I certainly want to give the impression that it was the only way to think, but at least she would be aware that the option exists.
We started out with boolean logic, introducing her to the idea of AND, OR and XOR. I used an example involving two entities that she would be familiar with, a cat and a dog, and ran through the various combinations (cat AND dog, cat OR dog, cat XOR dog etc). I was a little hesitant about doing this, considering that teaching the concept of the English Language definition of "or" to children is extremely difficult once you get into the specifics of the matter. She's not quite big enough to have a debate about disjunction, but we're working on that one. She was able to grok it straight away, and immediately started talking about how great it would be to have a cat.
Fortunately I was able to distract her by moving on to control flow, more specifically using the boolean logic skills she had just learned to discuss conditionals in an IF/THEN/ELSE form. I ended up scribbling a lot of pre-primary level pseudo-code down on a piece of paper for her to understand this. Drawing flow charts helped, too.
# I termed this as "If we had a cat and dog, we are happy,
# otherwise we're sad".
# Not exactly the most complex business rule in the world,
#but it gets the point across to a 5 year old.
IF (CAT AND DOG) { HAPPY }
ELSE { SAD }
I drew a quick flowchart of that code, showing the decision and then the two different results, and she immediately got it. The simple, one word results using terms that she was familiar with really seemed to click in her head. There's certainly something to be said for the universal appeal of a flow chart, too. Next time someone tells you that they don't understand your chart, tell them that a 5 year old can pick up the concept in a few minutes.
From there I was able to expand on control flow to include the concept of iteration and looping. By this point she was really into the whole cat analogy, and I was drawing pictures of cats under her strict direction. Pretty soon we had quite a few cats drawn on the page, so I said to her "what if you wanted to pet each one of those cats?". I got an enthusiastic response; apparently petting cats is a pretty popular activity amongst 5 year olds.
I initially made the mistake of trying to explain the concept of collections at the same time. We spoke about the cats living in a house, and how she might like to pet all the cats in the house. We ended up with the following scribble:
FOR EACH (CAT IN THE HOUSE)
{
PET CAT
}
This was great, but it lead to an off topic conversation about why there were no dogs in the house, and how if you had small babies then you might only want to have one cat or maybe even no cats at all, and if you had cats you might want some dolphins too because dolphins could live in a pool outside and dolphins are really cool. She was concentrating too much on the house and the endless possibilities of what could be put inside the house and less on the idea of the house being a container for cats. So I dropped the house concept, drew some more cats on the page, put a circle around the cats and pointed at them while running through the following example.
FOR EACH (CAT)
{
PET CAT
}
Removing a direct mention to the house cleared up the concept enough for her to focus on what I was saying. She could see the cats on the page, she knew that she wanted to pet each one, and she got the idea that she was going to pick up a cat, pet it, put it down, rinse and repeat until all the cats had been petted.
Then it was time to bring it all together. My daughter suggested that perhaps some cats might not be big enough to be petted. They might be babies that you need to be gentle with. Huzzah, we had our first business rule! Time to throw that in the mix.
FOR EACH (CAT)
{
IF (CAT IS A BABY) { BE GENTLE }
ELSE {PET CAT}
}
So now we had an example combining boolean logic, decision making and iteration/looping. It was almost like a mini JAD session, only with a 5 year old inventing random business requirements relating to cats. None of it went over her head, and I found that as long as I kept talking about something she was interested in then she'd quite freely discuss the topic and want to talk about more things that we could do to the cats. The interest was there, so she wanted to naturally evolve the conversation and learn more.
The two main ideas that I hope to tackle next are variables and the concept of ownership. Ownership will be a big one, as it will (hopefully) be a starting point for some basic OO concepts. This should lead on to separation of concern and a few other ideas. Now I just have to pick a language to demonstrate some of this stuff in. Oh look, KTurtle is installed on my machine!
