<<Previous | ToC
| Next >>
Until then, the computer does just what its program tells it to do, neither more nor less, and the program is what you told the computer to do, neither more nor less. So when the computer is rigid, controlling, or abusive, it reflects back on you. Today we will look at how to make the computer more polite, more willing to let the (human) user be in control. It's the difference between linear programming (Unix) and event-(human)-driven (original Mac) software. Most of that is appearance, because of course the computer still only can do what the programmer told it to do, but did the programmer tell it to demand "My way or the highway!" or did the programmer allow the human user to decide what to do next?
When you use a word processing or painting program, who decides what to do next, you or the computer? You do! You choose a tool, you decide where on the canvas or in the document to apply it, you decide what words to type or what color to add it, you the human. These programs were invented for the (original) Mac. The idea of a "human interface" didn't exist before 1984 (perhaps you saw the original Mac SuperBowl commercial).
Now, as a programmer, you have the same freedom, but at a second-order level: you get to write a program that lets the human be human. Or you can push people down to the level of the machine, allowed to do only what they are told. Superstar programmers lift everybody up.
Do you remember the first of the Six (or Five) Principles?
Sequence, doing things in order. With events we take that to a new level,
where the human (real world) supplies the order. Your program responds
to events and does what that event calls for.
I was going to except the Calculator because it has a single while-loop
around the whole program, the theory being that you replace the while-loop
with event handling. It works for the calculator, but not generally. In
fact it wouldn't work for the calculator either, except that you only have
two inputs, and they are very different in nature (1-letter command vs
a bunch of digits for a number). You still need to add extra code to cope
with deviations from the required sequence, operator before number, and
how do you know the number is done? That's why an ordinary calculator has
an Equal key; you didn't need it in our text version of the calculator,
because Java (and the Kitchen computer before that, both) required an Enter
key which served a double purpose.
"Any Event-Driven Program"It's the "Handle Events" part you need to think about carefully. The previous advice we gave about considering the inputs and outputs is a good place to start. Remember, the user controls the inputs, your program merely needs to handle them. In a way, this is much easier than trying to figure out the whole program. Just list all the possible inputs, then group them in some logical way -- perhaps by what kind of effect they have on your game (or whatever), or maybe what kinds of data they act on -- and then those groups form the next layer of your design structure, for example, the Calculator:
Initialize & Greetings
Handle Events
"Event-Driven Calculator"
Initialize & Greetings
Handle Events"Handle Events"
Number Keys
Operator Keys
Other Events {if any}
That might be enough to write code from. A more complicated program
-- say Rock-Paper-Scissors or Tic-Tac-Toe -- would require more layers.
Pong in GameEngine ----> ChromeBook start with: (Replit Pong video)
Event-Driven Calculator
Rock-Paper-Scissors with animation
Seaman with better graphics
<<Previous | ToC
| Next >>
Revised: 2022 October 17