How to talk to a computer


The first lesson you must learn in programming is that computer languages are not at all like the normal languages that people use. In fact, “language” is probably a bad word to use in programming. A computer “language” is more like a “set of commands” for making the computer do things. To learn programming, you must learn all the commands in the programming language. Each command has a very precise meaning and must be typed according to some very precise rules. One tiny mistake will certainly ruin the command.

This trips up all beginning programmers. Normal language forgives many errors. You can walk into a McDonald’s and say to the server something like this:

“Uh, I’ll have a Big… a Big… yeah, a Big Mac. No, make that a Quarter Pounder. With fries. Yeah, large. And a vanilla milkshake. No, chocolate. Medium. No, large. Oh, and make the fries medium size.” 

The server will have no problem getting the message: you want a Quarter Pounder with a medium sized serving of fries and a large chocolate milkshake. But a computer could never figure it out. 

Let’s imagine a fantasy in which the human server at McDonald’s is replaced with a robot. To place the same order by typing it into a console, you’d have to type something like this:

Order: 1 Quarter Pounder and 1 medium fries and 1 large chocolate milkshake

Suppose that you made a tiny goof and misspelled one of the words like this:

Order: 1 Quarter Pounder and 1 medium fries and 1 large choclate milkshake

The computer would go “BZZZZTT!” and say “SYNTAX ERROR!” and you’ve have to try again. Why? Because you misspelled “chocolate”, silly! It doesn’t know what “choclate” means. It won’t use a spell checker because programming languages absolutely, positively MUST get everything perfect. 

But computers aren’t the only ones to exhibit extreme sensitivity to syntax errors. In the right circumstances, people can be just as block-headed. How many times have you heard this line:

“We’re sorry, sir, but we cannot honor your request. You have not properly filled out form RC/22b, Authorization for Transmittal of Individual Confidential Information. Please review this form and fill it out completely and resubmit your application.”

If you think about it, this is really the same response as the computer’s syntax error. Both the computer and the bureaucrat respond to a communication that does not fit their required format with the same unyielding obtuseness.

Just to be fair, let me throw in another example:

“If the moment of inertia tensor is not diagonal, unstable perturbations will develop.”

Does this sentence make any sense to you? You have no context with which to understand it. How else could you respond to it other than to throw up your hands and say "Syntax error!”?

Here’s a quick and simple exercise you can try your hand at. It will show you how to talk to a computer using JavaScript. This is ridiculously easy — but it’s only the first example. There will be many more.

Exercise: Hello World

Here’s another exercise that gives you a chance to deliberately screw up and see what happens:

Exercise: Syntax Errors


Communication Responsibility
Whose fault is it when communications fail? Who has the responsibility for insuring that the communication gets through clearly: the speaker or the audience? We Americans, steeped in egalitarianism and a spirit of cooperation, tend to answer that both sides share responsibility for clear communications. I disagree, and I think that your experiences with computers will lend weight to my position. I think that the responsibility for clear communications falls squarely on the shoulders of the speaker.

In theory, the audience of a communication is supposed to give feedback to the speaker on how clearly the message is getting through. Thus, if you and I are conversing, and something I say doesn’t make sense to you, you are supposed to say, “Run that by me one more time, please.” This scheme insures that our conversation will move smoothly and efficiently.

In the real world, however, this seldom happens. Sometimes the audience doesn’t want to appear stupid by asking a dumb question. Sometimes the listener believes that his confusion is temporary and will quickly abate. Sometimes the listener is so completely lost that he doesn’t even know where to begin. Whatever the cause, he just nods his head knowingly and mutters, “OK”.

How then can we communicate well if our audience can’t be trusted to speak up when it is confused? There is only one sure-fire solution, and that is to assume very little of the audience. You must be pessimistic, assuming that everything you say is lost on the audience. You must drive home every single point with ruthless drive and determination. You must be a defensive driver, imagining what is going on in the mind of the audience, trying to guess where they might be tripped up next. This is the only way to communicate with confidence.

It is a hard lesson to learn, but the computer provides an excellent training ground. It assumes nothing, knows nothing. It has no context with which it can second-guess what you really meant to say. It can respond to your commands only in their absolute, literal sense. It will indeed drive you crazy. But it will also discipline you to think hard about exactly what you say. It is a sobering experience to have so many of your commands rejected as syntax errors — you never knew you were so sloppy a communicator. But once you learn to express yourself clearly and carefully, you will find that the number of syntax errors you generate will fall.

The lesson you learn in the process will benefit you in many areas other than computers. Precise communications are important in almost everything we do. How many arguments have you endured that were started by a misunderstanding? How many foul-ups have you gotten into because somebody didn’t express themselves exactly? I well remember the time my father drove 30 miles to pick me up “at the Doggie Diner on Main Street”. Neither of us knew that there were two Doggie Diners on Main Street. He went to one, I went to the other. If I had been more specific, the screwup would never have developed.

The most powerful demonstration of the crucial importance of precise communications is provided by an airline accident some years ago. As I recall, the tower had instructed the pilot, "Come down 3000". This was an ambiguous instruction; was the pilot instructed to come down to 3000 feet, or was he ordered to come down by 3000 feet? The pilot assumed the former, but the tower meant the latter. The pilot came down to 3000 feet; there was a mountain at 3200 feet; there were no survivors. Precise communications can be a matter of life and death.