How I learned to code

Amy J. Ko
Bits and Behavior
Published in
6 min readFeb 3, 2018

There are many paths to learning to code, but most of them are pretty random and unplanned. Even in this time of CS for All, most schools still don’t teach computer science, let alone have a community of people to mentor students. Instead, people stumble into it.

My path was no different. It started in 7th grade. I was in a class called “Transition Math”, which was basically a pre-algebra course with a sprinkling of statistics. The big focus of the class was equations and plotting.

This focus on plotting was key to learning to code. My math teacher decided that we should all buy TI-82 graphing calculators so we could learn how to enter equations and render plots. In the first week of class, he did a little tutorial, walking us through how to enter expressions and evaluate them. We thought the little console for entering expressions was pretty cool, because unlike a calculator, you could see the whole expression, the answer, and everything you’d entered in the past. The plots were even cooler: he gave us a bunch of inscrutable equations to transcribe, and out come all kinds of strange curves, asymptotes, and other foreign shapes. Most of the kids in the class, even those who weren’t really into math, couldn’t deny it: this little calculator was neat!

After plots, he had one more thing to show us. Not only could we enter equations and get answers, but we could save equations, so we wouldn’t have to type them in over and over. We just had to press the “PRGM” key, type it in there and give it a name, and it would be saved. And better yet, if we used a special command to prompt for input, we could enter custom values for the equation. Then, instead of laboriously typing an expression into the console, we could just type it once, then input a few values and get the answer. He thought that was pretty great.

The class was less impressed. Who cares about saving a few seconds of typing? I wasn’t impressed either. I want back to plots, changing them and adapting them, to see what kind of weird shapes I could make. It was a portable Processing for making art.

My pivotal moment came a few weeks later when one of my friends and classmates showed me a program his brother had gotten from a friend in high school. “Want to see something cool?” He pressed PRGM, launched a program named “Tetris”, and there it was: my beloved Game Boy game, running in full fidelity, on calculator. This. Was. Incredible. Immediately, I imagined the rest of 7th grade math, a Game Boy in disguise, freeing me from boring lectures about solving for x.

I asked him if there was a way to get the program. He suggested I transcribe it. We tried this for a few days, but after noticing the game was about 5,000 lines of instructions, we realized it was going to take too long, and be too error prone. But flipping through the calculator instruction manual, we learned there was a $5 link cable that we could mail order. I asked my mom for a check and put in the mail.

Six weeks later, it showed up, and I raced around before school trying to find my classmate. We plugged in the link cable, transferred the program, and there it was. I could now play Tetris too!

There was just one problem. My friend hadn’t ever let me actually play the game. I loaded it, started a round, and watched the pieces erase, pixel by pixel, and then redraw, pixel by pixel. It was functionally Tetris, but it wasn’t a game. It was molasses.

I was disheartened. I thought this was going to transform middle school for me, but instead I just had 5,000 lines of useless gibberish.

When I got home from school, I saw the instruction manual on my desk. I flipped through it. I remembered seeing two whole chapters about how to write programs. I started reading the first one. I learned things about how to print to a “console”, how to declare variables, how to return to previous lines with “goto” statements. Was it really this small set of commands that made Tetris work? Was it these little commands that made all games work? I was always curious about things, but this possibility, that games were just a small set of instructions, arranged in a very particular order, was too compelling to let go.

I read and re-read those chapters for the next couple of days. I started reading those 5,000 lines of code. Over the course of a couple of months, I figured out that some of those 5,000 lines of code were about keeping score. Some of them were about enforcing the boundaries of the well. Some defined the shape of Tetris pieces. And some rendered the pieces on the plot.

This rendering code is what I’d been looking for. That was the part that seemed to be so slow. Was it? I very carefully made my first change to the code, first remembering to write down the original logic so I wouldn’t lose it, and made it just render one pixel per piece instead of all of them. And it was fast! It was useless, but it was fast. The pixel rendering was definitely the slow part.

Over the next few weeks, I went back and forth between despair and hope. Some days, I didn’t think there was a way to fix it. Other days, I thought maybe there was a faster way to draw the pieces. One day, I realized that the pieces didn’t necessarily need to be drawn on the plot. If that was the slow part, why not draw them a different way?

My calligraphy class was the eureka moment. I was busy practicing my very fancy cursive, when I realized that letters are just shapes. Why can’t the pieces just be letters? I could build any Teris piece out of ‘|’, ‘-’, and other characters. And I could draw them on the console instead of the graph.

So I started devising a plan to tear out the plot rendering code and replace it with console rendering code. It was actually easier than pixels: the console was already a grid and there was a handy function for writing characters to a row and column in the grid. All of the same logic applied before, it just had to be translated to print functions instead. Oh, and I had to rotate the calculator to play, to make enough rows to play the game.

After a few days of tweaks and adjustments, I’d mapped every pixel-based output to a character, including points and prompts. And it was fast. Too fast. I even had to learn the sleep function to slow it down, which was helpful for controlling the difficulty of the game. I had Tetris!

I brought the link cable to class and immediately shared it with all of my friends.

They all immediately started playing Tetris, holding their calculators sideways.

And my math teacher immediately banned our calculators from class.

But that was okay. I’d found my medium. If code could make games, code could make anything, and that was amazing. Over the next year, I made text adventures, animations, puzzles, racing games and all kinds of other amateur content, all on my portable, battery-powered programming machine.

I eventually outgrew my TI-82. I learned BASIC. A Norwegian exchange student taught me Pascal every morning at 7am. I bought a computer graphics book and learned some C. I took a zero period CS class taught by a community college student and he taught me the algorithms and data structures he was learning. I took the AP CS exam in a broom closet, alone, in the dark. I’d found my medium.

--

--

Amy J. Ko
Bits and Behavior

Professor, University of Washington iSchool (she/her). Code, learning, design, justice. Trans, queer, parent, and lover of learning.