Listeners. More Fun Than Tijuana Bottle Rockets.
May 19, 2008
Listening is a very important interpersonal skill. It allows you to understand other people’s needs and motivations. As well, it prevents you from talking for five minutes straight before finding out she doesn’t understand English. *sigh*
In UI programming terms, listening is just as important. Listeners and events allow an application to react promptly to user input without having to continuously poll each component for change. Without them, your flashy UI will be as useful and interactive as a jpeg. Hence, we can think of listeners as the hyphen in “Human-Computer Interaction”. Yes, listeners are just that important.
Now, what happens if your listeners develop hearing problems? And what if they start eavesdropping on things they are not supposed to hear? Those are the problems I experienced this week. Some of the listeners I registered for basic events were behaving oddly. Sometimes they would respond correctly, but sometimes they would not. The friendly debugger informed me that the reason why they did not respond was because they were listening to another unassigned event instead. While I am sure there’s a perfectly logical explanation for this buried within the Flash+Flex event model, I still dropped quite a few hours trying to figure it out. After stepping through nearly every line in my code (it wasn’t that long) and still couldn’t find the problem, I was beginning to think it could be the fault of the Flash+Flex framework. As I was about to dive into the event dispatching code of the framework, I recalled the wise words of one of my mentors: “If you find yourself placing breakpoints on the SDK’s code, you may end up finding the bug, but you will not find happiness.” Agreeing with what he said, I stopped debugging and started rewriting a good chunk of the code. To put it briefly, the code works now.
Coming from a Java/.NET background, having to cast doubt upon the correctness of the framework is a new sensation to me. Logically, I do not believe it was the fault of Flash+Flex because listeners are the backbone of all that is interactive. If there are any problems with their listener code, I probably wouldn’t be the lucky first person to discover them. Still, it irks me that I was not able to figure it out grrrr…. On the upside though, I did learn a lot more about the listener/event model which may come in handy later.
Gonna celebrate this happy ending by blowing up some fireworks tonight. Wee.
But without having debugged the first version, how do you know the bug isn’t present in the second (just less frequent)?
The thought of not knowing what caused my program to do wonky things will cause me sleepless nights wondering “what if”.
It might not find you happiness, but it’ll find you peace