ThoughtFactory.CreateThought() A random collection of thoughts from an easily bored developer

13May/080

The Saga Continues

After the success of her first programming lesson, my 5 year old daughter was eager to start the next one.

Previously we had covered boolean logic and control flow, both of which she had no trouble with, so she was ready for something slightly more complex. I had a few ideas about what to talk about next, but I didn't want to decide until we were both sitting at the desk, ready to start the lesson.

The first lesson really drove home the similarities between teaching adults and children. It's all about being able to capture someone's interest for long enough to get your point across. The good thing about kids is that they make it fairly obvious when their attention span is waning and they are no longer taking on information. Adults have a nasty habit of trying to be polite, which only ends up wasting your time and theirs.

I left the decision to the last minute so that I could take my daughter's current demeanor, energy levels and alertness into account. If she was easily distracted then I'd want to avoid some of the more complex topics, and only explain short, easy to swallow chunks of information.

This turned out to be a good call. She had previously discovered TuxPaint on my Ubuntu box, and was already asking if we'd have time to play "the penguin game" (i.e. TuxPaint). I immediately knew my chances of having her undivided attention were shot.

As an aside, I highly recommend TuxPaint. I've installed it on her laptop, an old G4 iBook we had lying around, and she plays with it most nights. TuxPaint also has the honor of being the first open source project I've ever donated to. The guys who make it even offer really cool kid's shirts so your pre-schooler can show their support for open source software. It almost makes up for the fact that they don't sell FireFox shirts in kid's sizes. Almost.

I ended up ditching any ideas of discussing encapsulation for something much simpler. I figured that I could sell the concepts of variables and functions before she got bored and started asking about that silly penguin again. These two concepts would be enough to round out her understanding of some basic procedural programs, and probably allow us to actually create something cool.

Variables were easy to explain. I was considering starting with a brief overview of lambda calculus, but that might get us a call from child services, so i toned it down a little. At the heart of it, a variable can be explained away as an alias for something. It's just another way of referring to a particular "thing".

I appealed to her natural sense of vanity, something every 5 year old has more than enough of, and explained variables in terms of her age. She loves writing her name, so this was a good attention-getter.

EMMA'S AGE = 5
# I used this to explain what happens on her birthday
EMMA'S AGE = EMMA'S AGE + 1
EMMA'S AGE IS NOW 6

I explained that, after stating that her age was 5, we didn't need to say "5" over and over again. It was enough to say "Emma's age", because we knew that she was 5. I used her birthday as an example of changing the value of the variable. Every year she has to add 1 to her age, so on her next birthday she will be EMMA'S AGE + 1.

We tackled functions next. She loves baking, so I thought I'd use a concept of reusability that she would already be familiar with: a recipe. We wrote out a definition for baking a cake. Of course, I have no idea how to bake a cake, so I wouldn't recommend following the recipe...

BAKE CAKE()
{
	Add Flour
	Add Milk
	Add Eggs
	Add Sugar
	Add Butter
	Mix
	Put in Oven
}

Now that we knew how to bake a cake, we could bake as many of them as we liked.

BAKE CAKE
BAKE CAKE
BAKE CAKE
BAKE CAKE

After learning about functions and solving the world hunger crisis with cake we decided to call it a night.

Hopefully she's now learned enough to have a basic understanding of procedural programming, or at least enough to let her understand a simple programs, which is what we plan to do next. I don't expect her to be writing the next Crysis, but she should be able to sit over my shoulder and understand a Hello World or two.

Tagged as: No Comments
28Apr/081

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!

   
Sharing Buttons by Linksku