Computing · Stage 6

Comment Your Code

Programs & Judgement · comment your code · add comments and clear names so code is easy to follow, test and debug

✦ Computing📘 Stage 6 · S6⏱ ~13 min🧒 Ages 10–12★ Free to start
I can comment and name my code so it is easy to follow, test and debug.
Kavi the owl for Computing
📖

Kavi Opens an Old Program

Kavi opened a program from last month. "x = 0 … a1 = a1 + 1 — what does any of this do?" Kavi groaned. There were no notes, and every name was a single letter. So Kavi fixed it two ways. First, clear names: x became totalScore, a1 became isCorrect. Now each line reads like a sentence. Then a comment — a note for people that the computer skips: # give a bonus so hard questions feel fair. "A good comment says WHY, not just what," Kavi hooted. "Clear names and honest comments — now the program is easy to follow, easy to test, and easy to debug."

🎓

What your child will learn

1Clear names and good comments make code you can readThe computer runs your code no matter how you name things. But people have to read it, test it and fix it — including future you. Two tools make that easy. Tap each one.
2Same program, two ways to write itBoth of these do exactly the same thing. One is a guessing game; the other reads itself. Tap each to hear it.
3Read the plan without guessingHere is Kavi's quiz scorer, written cleanly. Every name says what it holds, and the comment explains WHY. Tap any line to hear it.
4Which ones make the code easier to follow?
5Spot the clearer choiceRead each pair, choose the version that is easier to follow, then reveal to check.
🔍

A peek inside

A variable holds the player's best-ever score. Which is the clearer name: h or highScore?
a name should say what the value holds — h could be anything

Try this at home: A note for people that the computer skips when it runs is called a ____.

Ready to play and learn?

Start the free interactive lesson, or print the handout for screen-free play.

Part of Computing · Stage 6 · S6 on KAVI Academy — a secular, whole-child learning platform for ages 5–12.