Anyone who has tried his hand at programming knows what an all-consuming endeavor it can be. But why is that so?
The image is one that everyone knows well, some of us from first-hand experience: the haggard programmer spending hour after hour at the computer in a quest to finish off some particularly challenging piece of code.
Sometimes it's an undergrad pulling yet another all-nighter. But frequently it's a professional at that keyboard, perhaps striving at a startup to realize an idea that came to her in a sudden flash of insight. Or maybe it's your pal in enterprise IT, too inspired to leave the office until he has vanquished the beast.
By now, these heroic stints are the stuff of legend and, for many whose life is software, standard operating procedure. Programming is a unique mix of engineering, mathematics, logic puzzles, and... and what?
Why, one wonders, does it get to be so addictive? What makes programmers so willing to work all day and all night, fueled on donuts and Jolt Cola, foregoing sleep and showers to get a bunch of symbols arranged just so? Novelists arrange symbols, too, but they're not known for endless stretches at the keyboard. They remember to eat, and to drink.
As explained to me years ago by Beau Shiel, a psychologist studying human-computer interaction at Xerox's famed PARC labs, the key to programming's hyper-engrossing nature can be found in the common pigeon. In the 1930s, B.F. Skinner began a series of experiments on these lowly birds, keeping them extra-hungry and confining them to small boxes. (During World War II, Skinner was funded to create pigeon-guided aerial bombs; Project Pigeon didn't get deployed, but it's a great piece of early cybernetic history.)
Inside each box was a small window, for signaling the bird, an electrical button for it to peck at, and a slot into which food pellets could be dispensed under electrical control. In short, a sort of feedback loop.
Pigeons could quickly be conditioned to peck at the button when shown a certain color, word, or other signal. But that was only the beginning.
Pigeons also could be taught that multiple pecks at a button would yield them a pellet. At first, it might be one peck, one pellet. After awhile, two pecks for one pellet. Then, three, and so on. In short, the pigeon could learn that by pecking long enough, it eventually would receive its reward.
Then came the devilish chapter of the experiment. Skinner set out to see how the bird would react to a randomized reward structure. This meant setting the number of pecks required to any of several numbers within a certain range. At first, the bird might learn that it had to peck once, twice, or thrice to get fed. Then, gradually, Skinner extended that range of possible pecks to include higher and higher numbers. Sometimes one peck was enough, sometimes two or five, but over time, in small adjustments, the range's average climbed higher and higher.
The pigeon's behavior? With this kind of "variable ratio reinforcement," as Skinner called it, the pigeon could be slowly conditioned to never stop pecking -- indeed, to keep pecking until it died of starvation. By making sure to feed the pigeon some minimum number of times even as the average number of required pecks got jacked higher and higher, the bird could be kept interested and pecking on and on. And on. Sooner or later, experience had shown, a pellet would arrive, so just keep pecking.
Scientists believe that it is exactly this kind of randomized payback that makes gambling so attractive and even addictive to humans. Indeed, casino operators use this insight to constantly fine-tune the odds in their slot machines, calculating exactly how frequent and how large payoffs should be to yield maximum profit.
Which brings us to programmers. Their payoff is simply seeing their latest collection of computer instructions behave as expected -- a genuine thrill, I can attest. Very often, tweaking, polishing, or embellishing a working piece of code makes it break, causing the programmer to try again, and perhaps again, until the program finally works again. As with the pigeon, the frequency of success is quite unpredictable, but given enough cans of Jolt, it is all but certain.
Your experience with overnight stints of programming? Tips for staying awake? Where to order take-out? Tell your obsessive-compulsive peers on the message board below.