« GDC 2011 - Late Wednesday to Early Thursday | Main | The Falling Frame »

March 16, 2011

The Apprentice

“Always two there are, a Master and an Apprentice...”

My ten-year-old son told me over the weekend that he has a school project where to understand colonial life, they are supposed to find a master craftsman and learn a skill from that craftsman in the way that skills were passed on at that time. After mulling it over for about three, maybe four seconds, I offered to teach him a little bit of video game programming¹ if he’d be interested.

He thought about it and told me the next day that he thought that would be pretty cool, and he seems really excited about it. Tonight we sat down and filled out his apprenticeship contract.

The Contract

After that we talked about how apprentices sometimes got something that they would need for their trade from their masters when they started out, and I told him that probably the most important thing to me when I’m writing a program is to have a good notebook to keep my thoughts in, both to write down ideas as I get them and to keep track of things I still have to do. I happened to have a couple 5”x8” Moleskines with quad lining and so I gave him one of those and we wrote his name and the date in it.

I showed him the notebook I use for personal projects at home, with pages of checklists for various projects in various stages of development. So, the first thing he wrote down in his notebook was “make check lists and keep organized.” So proud!

Well, that was enough of preparation so we jumped right in and I showed him a little something I’m working on, which is a simple tool I’m writing in Javascript and HTML5 for a home project². I showed him the few things it does (I wrote what I have in an hour or so this morning) and then we cracked open the source file and I showed him the script that produced what he was seeing. Part of what it does is to present an image centered on a canvas and allows you to zoom in and out on it, so I showed him how the program responded to keypresses (this took us on a quick detour into ASCII, but only just) and updated a bit of data storing how much to zoom the image and then I went into the place where the image is drawn on the screen and came across this:

    w = picture.width;
    zw = Math.round(w * zoom);
    var x = (dimx >> 1) - (zw >> 1);

Oh, right. Centering on the screen, just wrote this ten hours ago or so not knowing I’d be using it to teach, and there’s bit-twiddling in my very first example.

As it turned out, it was a perfect example. They’ve covered decimals enough for him to understand shifting in principle... he just hadn’t ever been exposed to binary. So we jumped in with both feet and I wrote down the number 12. “So,” says I, “you’re used to this number when it’s written in decimal, what is it?” “Twelve.” “Correct! I can also write that number using only ones and zeros!” And I wrote down 1100 next to it.

“Wait, so, how is that twelve?” I explained that just like with decimal numbers, each column was associated with a value. In decimals, it’s ones, tens, hundreds, and so forth, but in binary it’s just starting with one and doubling as you go:

On your fingers?

He totally got it, which was really thrilling for me. I joked that you shouldn’t really trust someone who can count to a thousand on his fingertips and he gave me a quizzical look, so we moved along.

Next I explained that what I was doing in my little bit of code I showed him was called “shifting” and diagrammed out what was happening, showing the result

Shifting and dividing

He thought that was really cool. So I took the TV remote and the pad of paper and explained how I was figuring out where to start drawing my picture so that it would be centered. We worked through the steps in the math to figure it out.

As it turns out, the little tool I’ve been fiddling with is for rotoscoping some images I have and want to use in a forthcoming personal project, should it see the light of day³. I went up on YouTube and showed J some early examples of rotoscoping in videogames -- particularly Karateka, which was one of the first graphical games I ever played on my old Apple II, and Prince of Persia, which came along a few years later. I even showed him bits of Another World/Out of this World in silent tribute to Chahi, who reminded me of the technique at his GDC postmortem4. We talked about how natural the motion looked even though the graphics were really really simple, and he thought that was really neat. I explained how games had started even simpler, and showed him a video of Pong, too.

This led us to a little discussion of how much more powerful computers are now. I dug up a picture of an Altair 8800, and showed him how there hadn’t really even been monitors on some of those early machines. I explained how I wrote my first programs on something that didn’t even have a hard drive, just floppy disks. I showed him how much performance had changed by opening up the “About this Mac” window in Finder and comparing that with the memory and performance of that Altair 8800. We used our new understanding of binary together to show the big difference between the two -- doubling performance *how many times*?

We were starting to run out of time, and so I wanted to leave him with a basic lesson for the day, even though I had kind of come into the whole thing unscripted. I returned to my program and pointed out that there were really two kinds of things going on in it, functions and data. I explained that a program was really just a bunch of functions that took data and turned it into other data.

He knew it was important. He jotted it down:

What's a program?

I don’t know what kind of game we’re going to end up with, but I’m glad we’re getting a chance to do it. I hope that we’ll be able to finish something by the time he needs to give his presentation in May, and I think that’s ample time. My apologies to all of you working on or waiting for Skyrim, but I think whatever J’s game is, it’s the most important game I’ll work on this year.



¹His brother did this two years ago and learned how to cook a particular dish from his mother. I think the emphasis is on the master/apprentice relationship and not the historical appropriateness of the skill.

²I’m not convinced that Javascript is the best approach for him, but there are some features which make it nice and a constraint that makes it fairly convenient. First, it has a super quick iteration time, edit text and reload in browser, which I really like -- there’s no compilation step. It also has the virtue of being web-friendly, and the web is something he already sort of understands and sort of uses. As for constraints, well, he won’t be working on things just at my house, so having an environment that I can throw on a thumb drive for him (or even email easily, should it come to that), is really nice.

³If it does, it releases Father’s Day. You heard it here first.

4Well, me and hundreds of others. :)

Posted by Brett Douville at March 16, 2011 09:31 PM

Comments

Awesome dad you are :D

Posted by: Tuim at March 17, 2011 02:25 AM

Great. Now we just need junior programmers out of college to be apprentices. Then we can pass the programming knowledge down to the next generation.

Posted by: Legend of Angband at March 17, 2011 03:32 AM

That is really awesome. Maybe I will recruit him to help me program my robots ;)

Posted by: Dennis M at March 17, 2011 10:46 AM

@Tuim Thanks! "Awesome" may be overstating, but I'm tryin', I'm tryin'

@Legend Agreed; if you're in a position to take someone under your wing, do so. :)

@Dennis He would freaking *love* that. My original introduction to assembly-level programming on the Apple II was in something that I think was called Robot War. :) He said something about programming a robot that would beat you at air hockey but dismissed it as "too easy".

Posted by: Brett Douville at March 17, 2011 11:19 AM

Awesome. Doubleplusgood.

Posted by: Chris C. at March 17, 2011 12:19 PM

This just made my day. "programs are functions that turn data into more data", at age of 10? I wish I had that!

Posted by: Aras Pranckevičius at March 17, 2011 03:22 PM

@Chris Thanks man, and please say hello to all our mutual friends in Oceania.

@Aras I wish I had it then too. There were inevitably discussions of how all data is stored as zeros and ones, but he hasn't yet asked if that is also true of programs. We will get there if we end up discussing how it is that his Javascript program is running in a browser. :)

Posted by: Brett Douville at March 17, 2011 04:39 PM

Great article, but good god man, green on yellow?! /asplode. Still, I enjoyed the post.

Posted by: Martin D at March 17, 2011 09:54 PM

Very nice. As a father of one daughter who absolutely won't have anything to do with our industry, congrats!

Posted by: Doug at March 17, 2011 10:25 PM

I taught myself to program from QBASIC's help files on my mom's computer when I was about eight years old. I wouldn't assume for one second that he's in over his head, especially with a teacher! I think you got him at just the right time.

The very first program I shared with another person was a console-based quiz game with questions based on my social studies book. With a teacher and a couple extra years under his belt, you might be able to guide him through setting up a GUI. The logic is really simple: RNG, a switch statement, matching multiple choice input, and keeping score.

For sure, though, let it be his project, and not your project with his input. He's not too young at all!

Posted by: Alex H. at March 17, 2011 10:48 PM

I think it's interesting how quickly you went to the low level. I've always thought people can grok "real" code more quickly than tutorials give them credit for, but it's still pretty bold to go right into the mathematical basis for it all. Kind of like learning set theory before addition -- a different pedagogical approach that could lead to a deeper and more intuitive understanding of the subject overall.

Another interesting/portable project you may want to look at is Hackety Hack.

http://hackety-hack.com/

I was really impressed with its progress last time I checked it out, but don't know how much it's stagnated since _why's disappearance. :-(

http://en.wikipedia.org/wiki/Why_the_lucky_stiff

Posted by: SJML at March 18, 2011 09:37 AM

@Martin Ha, I know, my color scheme is... well, it works for me. Green tahoma stays, I might have to find another background color. It was meant to evoke "vellum" but it may not be sufficiently subtle. Glad you enjoyed the post.

@Doug I'm lucky to have kids who are interested in what I do at work all day (or at least, what they *imagine* I do at work all day), but I would be amazingly proud of whatever they achieved in whatever interests they pursue :)

@Alex I started with Basic, too, and moved to assembly and a dialect of Forth available for the Apple II at the time; my first games were text adventures and text-based racing (and skiing, that sort of thing) games.

I am approaching all questions of design and how to do things with questions, rather than answers. "You'd like to make a baseball game? Tell me more." It's his project; I'm trying to teach him the basics of what's going on in that computer he's working on, the basics behind computer "science", that sort of thing. General advice is fine. The only thing I've cautioned him about is scale -- I explained that the games we play on the 360 or the PS3 take literally hundreds of years of effort (100 people for three years, say) -- this is particularly because he's learning to code at the same time as he is writing his first games. I think it's likely that when he first runs a working program that he wrote from scratch, he'll be hooked, just like I was and continue to be 30 or so years later.

Posted by: Brett Douville at March 18, 2011 09:47 AM

@SJML I admit, I probably wouldn't have gone straight to the metal if I had had some sort of lesson plan. Instead, it was more like, "Hey, can we spend an hour on this now?" and we dove right in and saw where looking at code took us. In this case, it went into a little culvert of "This is how the machines really work underneath".

My hope will be that he finds some of these little turns on his own and he takes them and runs with them if he's interested. He definitely had the little spark of pleasure of learning things that are fundamental (shift is division), so I'm hopeful that he'll also have the pleasure of finding things out.

Posted by: Brett Douville at March 18, 2011 01:12 PM