6/16/12

stories about programming

First Program

When I was 8 or so, my dad taught me how to program. We didn't have a computer, but he told me some BASIC commands. I was captivated by the idea. I wrote my first program on graph paper. Each square had space for exactly 2 letters. This seemed very computerish to me.

The program was a math game. You could choose which sort of problems you wanted to do: addition, subtraction, multiplication or division. Once you chose, it would give you a random math problem of that sort, and ask for your answer. Then it would tell you if you were right or wrong.

That week, I got the opportunity to type my program into an Apple 2e at my uncles house. I typed in all the commands, and it ran perfectly the first time. I was hooked.

The Idea of a Model

I was impressed by a 3d maze game I played. You could only look exactly north, south, east or west, and the maze was designed such that no matter where you were or where you looked, it always looked like you were looking down a hallway with passages branching off like open doors.

I decided to recreate this game. The first thing I did was draw a maze on graph paper. I designed it such that the view from any position would have the same property of looking like a hallway with passages leading off at various points.

Then I started manually drawing the view from each location in each direction, with the idea that I would add code after each view to take you to the appropriate next viewport depending on which direction you pressed.

This turned out to be a lot of work, and I was about to give up when my dad gave me an idea: "instead of drawing the views manually, why don't you store the location of all the walls in some variable, and then have the program figure out what the view should look like from where you're standing?" This insight was like magic, flipping a huge switch in my brain. This may be one of the most important lessons I ever learned in programming.

No comments:

Post a Comment