How my 12-yr-old son became a C# Programmer

My 12-year old son has been scripting since he was 7 or 8 and writing C# code for about 2 years now. Now for full disclosure, both my husband and I are software developers; my husband writes C++ and Java on the Linux platform but was a long-time Windows developer while I’m a C# .Net developer. We’d thought of eventually showing our son how to program but hadn’t planned on getting him started before he’d even learned long division.

The scripting was a bit of an accident. The PC game my son loved to play came with a full-featured game extension tool for users to develop their own modules and quests. Also included was the ability to write scripts to supplement the existing library with new functionality. It’s always exciting to invent your own modules and see how far you can push the envelope so this quickly became his favourite occupation.

The Copy-Paste Era

At first, his father provided him with a few key scripts that he could hook up to strategic locations and that would trigger a particular behaviour. For example, a “teleporter” script could be hooked up to a particular square in the game. When a character stepped onto the square, they would be “magically” transported elsewhere. But as any parent knows, children have many more hours for play than we parents have for fulfilling all their requests. Tired of waiting for daddy to have free time to write more scripts, my son begged for access to the scripting tool and started copying the scripts he’d already been given and tweaking them to fit the new functionality he wanted. That’s how he realized that programming was fun and not particularly difficult once he understood the logic and the syntax.

The Bounce-Stuff-Around-The-Screen Era

Writing scripts for your favourite game is one thing. But wouldn’t it be even more interesting to write a game of your own from scratch? So father and son sat down together and coded Pong, Asteroids, and other such simple games. At this point, it was mostly my husband coding but explaining what he was doing. This can keep a boy interested only so long and since we’d recently bought an XBox, it made sense to delve into XNA programming next.

My husband bought the wonderfully kid-friendly Learn Programming Now MS XNA Game Studio 3.0 book by Rob Miles (there’s a newer edition out now) and worked through the first few chapters with our son who took to it like a duck to water. Soon, he’d sped through the book and was writing all sorts of games that bounced a lot of objects on the screen.

That kept him occupied for a while but eventually, he realized there was more to the games he liked to play than images moving on a screen. He did not have the words to express what he was looking for but I could tell he wasn’t satisfied with the games he was producing. By then, he could handle simple C# data types, conditional statements and loops and had a basic understanding of classes and inheritance. He also understood XNA sprite batches, timers and the Draw method.

The Era of Enlightenment

I came back from Codemash v2.0.1.2 with the EverCraft Kata Dungeons&Dragons-style game instructions and, on a whim, suggested working on it with him. We’d do it using Red-Green-Refactor Test-Driven Development; an agile technique I’d been introduced to at Codemash and wanted to practice. As a huge D&D fan, I figured it was right down my son’s alley. I wrote the first failing test, he wrote the code to make the test pass and I refactored his code, explaining what I was doing and why. Then we traded places and he wrote a failing test for the functionality I was to implement next.

We spent hours implementing the character class with its hit-points, abilities, and more and by the end of that day, my son’s eyes were shining. Finally, he’d uncovered the missing piece of the puzzle. He now knew how to add substance to his games: that logic that made characters tick and non-visual things happen. We did a few more sessions but that project was abandoned long before we reached the end of the Kata document in favour of the sims-based game he’d been aching to write; the one where a few thing might move on the screen but many of the underlying parameters change as time passes.

And that’s when he started flying solo. Now, I hardly ever see his code but the things he creates have me wondering if I could do half as well.