Saturday, May 19, 2007

Bring to a boil: programming with cairns

I'd like to see more computer language instructions like the "bring to a boil" instruction you see in recipes. "Bring to a boil" doesn't tell you to put the pot on the stove, or how you turn the burner on, or how long it takes to boil. In fact, that may vary based on your altitude, the quality of your tap water, and the shape of your pot.

"Bring to a boil" jumps ahead past a bunch of obvious steps. It's not just like a subroutine call, encapsulating a handful of steps for brevity; it just describes the endpoint of a bunch of steps, and it's assumed you can find your way there yourself.

Finding its way there itself is something computers can do. Algorithms to traverse mazes are not that tricky, and in some limited domain, figuring out how to accomplish some process could be likened to navigating through a maze. In some limited domain where an algorithm can be generated to get from here to there, why not give programmers that for free?
Presuming that automatic programming is hard in the general case, but easy in sufficiently constrained cases, then programmers should be able to set a series of cairns for the compiler to follow, each close enough to the last for automatic programming to find its way, but far enough apart to save having to type in a lot of tedious steps.

The other nice thing about this kind of instruction is that it entails a test. Often we write code that clanks along like an insane robot, following instructions without checking every so often to see that it's still on course. "Bring to a boil" isn't the sort of instruction that can accidentally be followed when you're in the bedroom instead of the kitchen, blindly going through the motions of turning on an imaginary stove while standing in front of the laundry hamper.