enk@corona (Edan Kabatchnik) (08/17/89)
>Well, some folks think Unix should be done away with ;*). I think that if >you gain some experience with the Mac, you'll find that the main event >loop is a good way to write event-driven programs, and this is central to >implementing the Mac user interface. There is absolutely nothing >difficult about writing an event loop. It is not the same thing as >writing a program to run under Unix or DOS or VMS, but so what? Granted, (parts of) UNIX should be done away with. But, there is a superior form to the main event loop: callbacks (found in X and Xerox Artificial Intelligence Workstations from which the Macintosh developed its user interface.) Instead of having to dispatch on every possible event in the main event loop, one establishes a hook that is automatically called when an event takes place. Example: when creating a menu, each item that can be selected in the menu is given the address of the function which should be called when that item is selected. So, the programmer does not call his menu handler explicitly; rather, it is "magically" called by the menu code in the toolbox when the selection occurs. This takes away all the pains of the main event loop. (The main event loop is reduced to a few standard lines of code that need not dispatch on event.) So much code has been written for the Macintosh which works without callbacks, making it unlikely that future versions of the system will take advantage of callbacks. But, if Apple could figure out a way of making both systems work, then future programmers would be spared a great deal of pain. +----------------------------------------------------+-------------------------+ |There is a club if you would like to go. | Edan Kabatchnik | |You could meet somebody who really loves you. +-------------------------+ |So you go, and you stand on your own. | MIT | |And you leave on your own. | enk@wheaties.ai.mit.edu | |And you go home, and you cry, and you want to die. |Schlumberger Technologies| | - The Smiths | enk@slcs.slb.com | +----------------------------------------------------+-------------------------+
ingemar@isy.liu.se (Ingemar Ragnemalm) (08/17/89)
enk@corona (Edan Kabatchnik) writes: > Granted, (parts of) UNIX should be done away with. But, there is a >superior form to the main event loop: callbacks (found in X and Xerox >Artificial Intelligence Workstations from which the Macintosh developed its >user interface.) Instead of having to dispatch on every possible event in the >main event loop, one establishes a hook that is automatically called when an >event takes place. > Example: when creating a menu, each item that can be selected > in the menu is given the address of the function which should > be called when that item is selected. > So, the programmer does not call his menu handler explicitly; rather, it >is "magically" called by the menu code in the toolbox when the selection >occurs. This takes away all the pains of the main event loop. (The main event >loop is reduced to a few standard lines of code that need not dispatch on >event.) > So much code has been written for the Macintosh which works without >callbacks, making it unlikely that future versions of the system will take >advantage of callbacks. But, if Apple could figure out a way of making both >systems work, then future programmers would be spared a great deal of pain. From the programmers point of wiew, TransSkel (by Paul duBois) does just that. For each menu and each window etc, a ProcPtr is installed, telling TransSkel what to call when that particular item gets a particular event. A similar (more limited) package is SimpleTools by Erik Kilk, and there are others as well. So, the problem is solved, I think. Ingemar Ragnemalm -- Dept. of Electrical Engineering ...!uunet!mcvax!enea!rainier!ingemar .. University of Linkoping, Sweden ingemar@isy.liu.se