February 3, 2009
MarkBernstein.org
 
Follow me on Twitter

Debugging and Forest Ogres

Chris Mills and Halvord Steen discuss Javascript Debugging in A List Apart.

Agile pioneer and propher Kent Beck (who, astonishingly, is looking for a job) talks about Untangling Spaghetti: debugging non-terminating object programs. This is an unfortunate title, because spaghetti means “tangled control flow” while Beck explores how to disentangle mutual recursion between multiple objects. This kind of bug doesn’t happen all that much, but change management in Tinderbox views is inclined to exactly this mishap: when something changes, Tinderbox needs to update windows and agents and such, and this can lead to more changes, and more updates. If you are careful, eventually everything that needs to be updated will be updated; if things go awry, you can end up spinning wheels indefinitely.

Fortunately, there’s a good solution: instead of responding immediately to every change, you tell Tinderbox to stop, take a deep breath, and make a list of everything that needs to be updated. Look at each update, and make a list of everything that the update will change. Eventually, you've got a long list of changes; now, make them all, and clean the slate.

Beck mentions that these problems don’t seem to crop up all that often, but they can be tricky to fix when they do appear. I think it’s worse than that. Everyone learns to recognize infinite recursion: function a(){ a(); } That's easy. And simple mutual recursion is pretty easy too: A calls B(), and B calls A(), and off we go. When you have six or seven objects weaving back and forth, noticing the cycle can be tricky. I think we all have a certain fear that, someday, we’ll hit the fractal program that baroquely loops in a different pattern each time. It’s the modern programmer’s ogre in the forest.