Saturday, March 17, 2007


Part of learning how to program is learning a set of idioms, conventional ways of solving recurring problems. At first you have to think about these explicitly, but over time they become second nature, part of the way you see the world and act in it.

For example, suppose you want to create a toggle, a switch that goes to its opposite value when you press it. If it is on, it should turn off, and if it is off, it should turn on. (And by convention, let's assume On = True = 1 and Off = False = 0.) Many beginning programmers write something like this: IF SWITCH IS 1 THEN SET SWITCH TO 0 ELSE SET SWITCH TO 1. There is nothing wrong with this code; it is easy to understand and works fine. More experienced programmers have learned (or discovered for themselves) that they can say SET SWITCH TO 1-SWITCH instead. So if the value of the switch is 0, then 1-0=1 and if the value of the switch is 1, then 1-1=0. Same behavior, different idiom.

In fact, the idea of a toggle is fundamental enough that it recurs across domains. In electronics, for example, there is a well-known circuit called the flip-flop. It can be implemented in different ways (i.e., with different idioms) but all flip-flops can store a single bit, a single On or Off value. Miniaturized and in bulk, these tiny toggles serve as memory for computers.

In graphical user interfaces, the well-known check box is a toggle. If you take apart retractable ballpoint pens, you will find a number of different mechanical idioms for implementing two states for the nib: In and Out. Although we don't often think about retractable pens in these terms, each has at least a single bit of memory. If you dance the foxtrot, a series of left turns can make you and your partner toggle forwards and back. The same effect can be achieved in other styles of dance with other idioms.

The idea of a toggle becomes part of a designer's toolkit, regardless of the expressive medium he or she is working in: circuitry, software, human interaction, mechanics, dance. As computing becomes pervasive, digital historians will need to find and master the idioms that best help them convey a sense of the past to their different audiences.

Tags: | | | |