Chapter 1: Whirlwind Tour of Quantum Programming
Overview
I have found out there ain't no surer way to find out whether you like people or hate them than
to travel with them.
—Tom Sawyer Abroad [Mark Twain]
The triumph of the graphical user interface has been one of the most impressive developments in software
during the past three decades.
[1]
Today the concept is so familiar as to need no description. Although from the
beginning, windows, icons, menus, and pointing have been intuitive and easy to grasp for users, they remain a
challenge for programmers. The internal GUI architecture baffles many newcomers, who often find it strange,
backwards, mind−boggling, or weird. GUI programming is different because unlike traditional data
processing, it is entirely event−driven. Events can occur at any time in any order. The application always must
be prepared to handle them. GUI is an example of a complex reactive system.
You don't need to look far to find other examples of reactive systems. In fact, CPUs of all PCs, Macs, and
other general−purpose computers consume only about 1 percent of the worldwide microprocessor production.
The other 99 percent of microprocessor chips sold every year end up in various embedded systems, which are
predominantly reactive in nature. Yet, in spite of this ubiquity, the code found in most of these systems is
notoriously difficult to understand, fix, and maintain. Theoretical foundations on how to construct such
software have been around for more than a decade; however, these ideas somehow could not make it into the
mainstream. Quantum Programming (QP) is an attempt to make the modern methods more approachable for
programmers. QP is a set of straightforward design patterns, idioms, concrete implementations, and
commonsense techniques that you can start using immediately without investing in sophisticated tools.
[1]
The concept of the windows, icons, menus, and pointing (WIMP) interface was first publicly displayed by
Doug Englebart and his team from the Stanford Research Institute at the Western Joint Computer Conference
in 1968 [Englebart+ 68].
1.1 The Ultimate Hook — Anatomy of a GUI Application
The early GUI designers faced a formidable task. On the one hand, a GUI application must be virtually
infinitely customizable to allow anything from nonrectangular windows to splash screens and dazzling screen
savers. On the other hand, the system ought to impose a consistent look and feel, and applications content
with this standard behavior should be simple. How would you reconcile such conflicting requirements?
Today the problem seems easy — the trick is to use the "Ultimate Hook" [Petzold 96]. The idea is brilliantly
simple. The GUI system (e.g., Windows) dispatches all events first to the application (Windows calls a
specific function inside the application). If not handled by the application, the events flow back to the system.
This establishes a hierarchical order of event processing. The application, which is conceptually at a lower
level of hierarchy, has a chance to react to every event; thus, the application can customize every aspect of its
behavior. At the same time, all unhandled events flow back to the higher level (i.e., to the system), where they
are processed according to the standard look and feel. This is an example of programming−by−difference
because the application programmer has to code only the differences from standard system behavior.
Independently, David Harel applied the same idea to the finite state machine formalism [Harel 87]. Around
1983 he invented statecharts as a powerful way of specifying complex reactive systems. The main innovation
of statecharts over classical finite state machines was the introduction of hierarchical states. To understand
Chapter 1: Whirlwind Tour of Quantum Programming 11