I love debuggers. I really do. I’ll spend three hours wiring up a a new debugger/IDE configuration to get five minutes’ use out of it. But anything becomes a crutch if you lean on it all the time. (Plus your armpit gets all funky.)
I’ve just been working through a very odd bug in a Flex application we at roundpeg are building for one of our customers. We have a DataGrid with a list of people–shocking, I know–and one of the testers noticed that after he clicked on a person who shared the same last name as another person in the list, he was not able to select the second co-surnamed person. He would click, but nothing would happen. And it only seemed to happen with entries in the list who shared this field in common.
So, off I go into the debugger. I’ll save you the details because they’re tedious and boring, as the whole experience was, but suffice it to say that four hours later, at line 8,351 of mx.controls.listClasses.ListBase.as, I decided that the approach I was taking was suboptimal.
So I stopped debugging. And I started to comment out code. I commented out a bunch of code in the code-behind class for my list, and what do you know, the problem went away. I started uncommenting line-by-line, and, voila, found a single line in that class that was the jumping off point for the problem. Now of course I wasn’t done there–that single line invoked a controller method that had a cascade of effects, and I was soon commenting out message dispatches, narrowing them down to the one that, again, eliminated the problem (along with other important functionality) when it was commented out. Then it was on to searching for and commenting out methods that were receiving the error-inducing message (one of the drawbacks of an event-driven system, that searching is). And finally I found the line in our code that was causing the problem: We were setting the selectedItem property of the list at the same time it was being set by the DataGrid’s own click handler.
It wasn’t necessary for us to do this–I can’t imagine a case where it would be, since the selected item already was the object in question, but it certainly shouldn’t have caused this bizarre behavior. It wasn’t for nothing that the code existed; it was there to cause the list to select an item newly added by another interface, but happened to reuse a message that was also emitted when a new item in the list was selected.
My best guess (and at 4 AM with the problem fixed I wasn’t interested in exploring it any more) is that somehow the object comparison was getting muddled. It’s a lousy guess, since object equivalence should be a matter of comparing the UIDs of two references, and the “U” in UID is for Unique.
To make a long story… well, not any longer, the title references a common tension in the scientific community between theorists and experimenters. It isn’t always present, and from my position as an avid follower but non-practitioner of physics I’m not aware of it becoming anything like, say Cowboys versus Redskins, or UI engineers versus server-side engineers. But the tension exists, and for good reason–both approaches are essential, but they’re different, and at different points in time, under varying circumstances, one or the other will be adding more value to solving the problem at hand.
In my case, I began with the theory. “I’m going to do this the right way,” I thought. “I’m going to use the debugger and really follow what’s going on, until I understand the whole process and can pinpoint exactly where the failure occurs.” That is a perfectly reasonable, very-often-correct approach. And if my goal was to understand the problem, that would be the right approach. But it wasn’t, not really. My goal was to fix the problem. Of course I needed to understand it enough–enough to have a general idea of the processes at work, and enough to have narrowed down the list of culprits from the entire universe (or at least the body of source code from Flash Player down to the hardware).
But as the hours wore on and yesterday turned in to tomorrow, I just needed to fix the damn thing. And that’s where experimentation took over.
A theory predicts what is. An experiment proves what isn’t. Per Holmes:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
Sometimes you just need to put down the book, pick up the magnifying glass, and start eliminating the suspects..