Teaching our five year old to code by cheating

Teaching our five year old to code by cheating

My wife and I became reluctant homeschoolers this year – choosing to teach our five year old daughter without the our school's remote learning. Rachel teaches Reading, Writing, Arts, and Science. My job is Math, Chess, and Technology.

I started programming on a TRS-80 when I was six or seven. Back then, the computer booted into BASIC, the most approachable programming language of all time. Hello World in BASIC looks something like:

10 print "hello world" 
20 goto 10

Programming in BASIC was the most instant gratification you could get on a TRS-80. There were few games and no Internet. Had I been introduced to a different programming language at a different age, I'm not sure I would have taken to it.

That's been a problem I've been wrestling with when introducing our daughter, Emma, to programming. Modern developer environments have a lot of friction and overhead. We've played with Swift Playgrounds, which is great for introducing programming concepts, but feels like you're writing instructions inside a video game as opposed to harnessing the the raw power of code to control the computer.

A colleague recently introduced me to pg-basic on repl.it, which recaptures the simplicity of writing BASIC on a TRS-80.

Emma and I are working on addition. She likes video games and coding, so I figured we could create a game to practice math. The general idea is: pick two numbers at random, ask her to add them, give her points if she gets it right. We did it in Python, as the code was't that dissimilar to its Basic equivalent.

Go ahead, run it. (And edit, if you wish.)

I composed the code with her sitting next to me, asking for her suggestions along the way.

  • "What should we name this variable?"
  • "How many points should you get when you get one right?"
  • "How many points do you need to win?"
  • "What should it say when you win?"

Then I made her a deal: if she won the game two times, she could cheat and change the code. She loves cheating.

She quickly figured out she could change the lines that generate numbers to:

lulu = 0
boonie = random.randrange(11)

Math problems got easier. Then she changed it to:

lulu = 0
boonie = 0

Problems got a lot easier.

She still had to answer a bunch of questions to win the game, and typing zero and enter repeatedly is hard work, so she changed the looping condition to:

while points < 1:

It may be the first time in her short educational career when she's had control over the quiz, instead of the quiz having control over her.

Thinking back to how I started writing code, it was copying a few dozen lines of BASIC out of the back of 3-2-1 Contact, getting it to run, and then tweaking it. Today, when I learn a new language or service, it's "copy, paste, edit."

Composing along side Emma and letting her edit seems to be a winning strategy. Yesterday, after making a modification, she thought for a few seconds, turned to look at me, and said, "... I can use code to do anything."

She's starting to get it.