This is ONE OF 2 responses to volume 3, Holly Card Number 3 ("Learning Hypertalk")...
What a question! I hardly know where to begin. But first let me ask you a similarly difficult question. Can you tell me how music works, I mean like how a symphony is constructed and what YOU hear when you listen to one? Tell me something about music theory! I really want to know!
Now then, a program, any program, is in essence a list of instructions not unlike a recipe. And a computer is simply a machine that can recognize and follow simple instructions. You could build a computer out of anything, waterfalls or dominoes or even slabs of protoplasm, but we build most of ours out of sand (that is, silicon).
Everything you do to your Macintosh, and everything the Mac does to you, happens from inside a program. When you turn on the machine, it automatically runs a very simple program that looks around for more programs to follow. When it looks on the hard disk (or on a diskette) it soon finds another program called the Finder which tells the machine to whip up a gray desktop, install a trash can and some menus, etc. As soon as you double click on a program icon like MacWrite or MacPaint, the Finder passes the baton to this new program and the machine starts following a new set of instructions. This process is known as running a program or, in Macintosh parlance, launching an application.
The instructions that the machine itself can actually understand are VERY simple. Things like "Add x to y" or "Jump to instruction number 15" or "If x is greater than y, then stop." Programming at this level is VERY tedious. Fortunately, other people have developed high level languages with much more powerful instructions like "Draw a circle" or
"Sort all the cards in this stack."
A language is a set of fancy instructions that comes with a program that automatically translates each fancy instruction into a long list of simple instructions. There are two types of language programs: compilers and interpreters. Compilers do all the translation at once and produce a separate machine language program. Interpreters do the translation AS the program is running. Interpreters tend to be slower than compilers but easier to program with. HyperCard is an interpreter program for the HyperTalk language.
There are hundreds of different computer languages, but most of them, like BASIC and FORTRAN, take the form of numbered lists of instructions. You can enter the list just as you would a word processing document, and when the computer executes it, it does so one step at a time.
HyperTalk is slightly different. It is an "object oriented" language, which means that it's instructions are divided into a host of simple "scripts" - one for each object. And what IS an object? A button is an object; a field (those boxes we type text into) is an object; a card is an object; even a stack is an object. A HyperTalk program, or "stack", is a hierarchical set of nested objects and each object waits for something to happen to it and then reacts according to the instructions in its script.
What can happen to an object? If it's a button then someone can click on it. If it's a field then someone can type in it. If it's a card then someone can leave it and move on to another card. Dozens of different things can happen to objects. Objects can even wait for the clock to strike midnight.
Writing a HyperTalk program, then, is like creating an ecosystem. You begin with the arctic whiteness of a blank card. You then add more cards and give your new world form and shape by adding backgrounds with pictures and lines and boxes. You then people your world with strange new critters: buttons and fields. You give each button a distinctive shape and size and a name to call it by. And you define its behaviour by giving it a script.
The card you're looking at now has 23 buttons (some of them hidden) and 3 fields. The script which belongs to that downward pointing arrow is:
go to card "VC 3 Holly 3" of stack "Voices 3"
That is, "When someone releases the mouse button over me, go to Holly card number 3." This script was actually written by another script
(objects can push other buttons and type bits of text and pull out desk accessories from the menu and even create new objects!).
The act of creation is as simple as selecting an item from the menubar. To create a new stack you simply choose "New Stack" from the File menu; to create a new button, choose "New Button." HyperCard also provides MacPaint-like tools to help create backdrops. Once an object is created, you can then open it up and mess with its innards (by selecting an opening tool and clicking on the object).
What do objects look like inside? When you open an object a window appears with buttons and fields that define its characteristics. You can then push the script button to reveal a big scrolling text field. The script is simply a bunch of text which can be entered and edited just like a memo or a letter.
When I create a new stack, I usually begin by jotting down notes on a yellow pad. I try to get it clear in my mind exactly what I want the stack to do and what I want it to look like. I then try to figure out the best way to do this (there are always at least a dozen different ways to do something in HyperTalk).
The first blank card is every bit as terrifying as a blank canvas or a blank page. So I quickly scatter a few buttons across the surface, open 'em up, and start typing in their scripts. In order to compose a program you have to break the overall task into smaller sub-tasks and then tackle each sub-task one at a time. Each object is performing a sub-task and its task can in turn be broken down into even smaller routines.
I have kind of a fuzzy version of the HyperCard Interpreter in my head, and as I type in the instructions I run the program through in my mind and try to guess what HyperCard will do with it. There is much muttering and brow furrowing at this stage and at times I leap up from my keyboard and begin to pace back and forth "No no no! That won't work at all!"
Finally I finish the script, close up the button, and push it to see what happens. At this point there is more cursing and abuse of nearby inanimate objects. And more pacing. I run the script through in my mind step by step and try to figure out what went wrong. Sometimes it takes a fraction of a second, sometimes a long and angry afternoon, but eventually there comes a blinding flash of light. Aha! I race to keyboard, enter my changes, and push the button again. And again. And AGAIN.
When the button is finally doing what I want it to, I move on to the next one. And when the whole stack is finally working, I do a little dance. And that's what it's like to program.