Introduction

I vividly remember writing my first program. (My memory is pretty horrible; I don’t vividly remember many things, just things like waking up after oral surgery or watching the birth of our children or that time I was trying to flirt with this girl and she told me that my zipper was down or when I set my shoes on fire in my middle-school gym class or writing my first program…you know, things like that.)

I suppose, looking back, that it was a fairly ambitious program for a newbie (twenty or thirty lines of code, I think). But I was a math major, after all, and we are supposed to be good at things like “logical thinking.” So, I went down to the Reed College computer lab, armed only with a book on programming and my ego, sat down at one of the Unix terminals there, and started programming. Well, maybe “started” isn’t the right word. Or “programming.” I mostly just sat there, feeling hopelessly stupid. Then ashamed. Then angry. Then just small. Eight grueling hours later, the program was finished. It worked, but I didn’t much care at that point. It was not a triumphant moment.

It has been more than a decade, but I can still feel the stress and humiliation in my stomach when I think about it.

Clearly, this was not the way to learn programming.

Why was it so hard? I mean, there I was, this reasonably bright guy with some fairly rigorous mathematical training—you’d think I would be able to get this! And I did go on to make a living programming, and even to write a book about it, so it’s not like I just “didn’t have what it took” or anything like that. No, in fact, I find programming to be pretty easy these days, for the most part.

So, why was it so hard to tell a computer to do something only mildly complex? Well, it wasn’t the “mildly complex” part that was giving me problems; it was the “tell a computer” part.

In any communication with humans, you can leave out all sorts of steps or concepts and let them fill in the gaps. In fact, you have to do this! We’d never be able to get anything done otherwise. The typical example is making a peanut butter and jelly sandwich. Normally, if you wanted someone to make you a peanut butter and jelly sandwich, you might simply say, “Hey, could you make me a peanut butter and jelly sandwich?” But if you were talking to someone who had never done it before, you would have to tell them how:

  1. Get out two slices of bread (and put the rest back).

  2. Get out the peanut butter, the jelly, and a butter knife.

  3. Spread the peanut butter on one slice of bread and the jelly on the other one.

  4. Put the peanut butter and jelly away, and take care of the knife.

  5. Put the slices together, put the sandwich on a plate, and bring it to me. Thanks!

I imagine those would be sufficient instructions for a small child. Small children are needlessly, recklessly clever, though. What would you have to say to a computer? Well, let’s just look at that first step:

    1. Locate bread.

    2. Pick up bread.

    3. Move to empty counter.

    4. Set down bread on counter.

    5. Open bag of bread.

But no, this isn’t nearly good enough. For starters, how does it “locate bread”? We’ll have to set up some sort of database associating items with locations. The database will also need locations for peanut butter, jelly, knife, sink, plate, counter….

Oh, and what if the bread is in a bread box? You’ll need to open it first. Or in a cabinet? Or in your fridge? Perhaps behind something else? Or what if it is already on the counter? You didn’t think of that one, did you? So, now we have this:

  • Initialize item-to-location database.

  • If bread is in bread box:

    • Open bread box.

    • Pick up bread.

    • Remove hands from bread box.

    • Close bread box.

  • If bread is in cabinet:

    • Open cabinet door.

    • Pick up bread.

    • Remove hands from cabinet.

    • Close cabinet door.

And on and on it goes. What if no clean knife is available? What if there is no empty counter space at the moment? And you’d better pray to whatever forces you find comfort in that there’s no twist-tie on that bread!

Even steps such as “open bread box” need to be explained…and this is why we don’t have robots making sandwiches for us yet. It’s not that we can’t build the robots; it’s that we can’t program them to make sandwiches. It’s because making sandwiches is hard to describe (but easy to do for smart creatures like us humans), and computers are good only for things that are (relatively) easy to describe (but hard to do for slow creatures like us humans).

And that is why I had such a hard time writing that first program. Computers are way dumber than I was prepared for.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.211.70