Teaching Scratch taught me how to read my own code

I teach programming to school students in Sohag, and I built the exam tool they use. What they get wrong is what I get wrong, and the fix was the same for both of us.

Articles

November 7, 2026· 7 min readTeachingTeachingJavaScriptScratchEducation

Through GMT I run the programming side at a school in El Kosheh, in Sohag. Students there work in Scratch, then C++, then web. There is a competition every year, and the projects are theirs, not mine.

Teaching changed how I write code, and one project changed how I think about checking it: scratch-final-exam, a small tool where a student builds a Scratch-style program from blocks and the tool grades it.

The bug is almost never where they think it is

A student's sprite does not move. They point at the movement block. The problem is three blocks up, where the variable was never set.

Watching that happen two hundred times taught me the thing I now do on my own code: I read the sequence before I read the line. Not "what does this line do" but "what had to be true for this line to work". Nine out of ten times the answer is a value that was never set, or was set once and then changed.

Loops and variables, in that order

If I had to pick the two ideas students lose marks on, it is these.

Loops. They repeat a block ten times by copying it ten times, because copying is what they know. The first time they need eleven, the lesson lands. The way I teach it now: "make it once, then tell the computer how many times".

Variables. A variable is a box with a name. You put something in it, and later you can look inside. That is it. But a student who has never had a name that changes will write score + 1 and never store it, and the score stays zero forever. The box metaphor works, and so does making them physically write the value on paper each time the loop runs.

The third thing, which is not a concept but a habit: read the error. Not "it doesn't work". Which block, which line, which value.

Grading blocks is not grading text

The tool exists because checking a Scratch project by hand does not scale. Thirty students, one project each, and the projects are drag-and-drop, so there is no text to diff.

So the project is data. Every block is an object: its type, its inputs, and its children. The builder renders those objects as draggable pieces, and saving writes the tree back out.

Grading walks that tree. For a task like "repeat the jump three times", the check is not "does the source contain a repeat block". It is: find a repeat block, check its count, and check that the block it wraps is the one the task asked for. Two students can build that differently and both be right; one student can have the right text and the wrong nesting.

The first version compared strings, and it was wrong in both directions: it passed programs that did nothing and failed programs that worked. Walking the tree fixed it, and it is the same lesson as the parallax page: check the structure, not the surface.

What the tool does not do

It does not teach. It grades what a student built, and it tells them which task failed, not why. The "why" is still a person sitting next to them, asking "what did you want it to do".

I also kept the exam short on purpose: three tasks, one of them open. The open task has no automatic grade at all, because the interesting answer is never the one the checker expects.

What I took back to my own work

  • Name things so the name says what it holds. Students name variables x and y, then cannot read their own program a week later. I have done exactly that in production code.
  • Write the smallest version that runs. The students who finish first are the ones who build one block, run it, then add one more. The ones who build everything and press play at the end are the ones who cannot find their bug.
  • A working demo is not a finished project. Their competition entries always run, and the ones that win are the ones where someone thought about what happens when the user does the unexpected thing.

Why I still teach

I am a full-stack developer and a company founder, and teaching is the part of my week that keeps the rest honest. You cannot hand-wave a concept to a twelve-year-old. Either you can explain state in one sentence, or you do not understand it as well as you thought.

That is the whole trade. They get a teacher, I get a compiler for my own explanations.

→ All articles