Dynamic browser-based interfaces are nontrivial, in the sense that your math teacher might talk about things being nontrivial. That's fancy talk for being really hard.
You get plenty of widgets to play with. Creating them and slapping them up on the screen is fairly easy. Wiring the widgets up to javascript code is actually quite trivial.
The trick is when you want to make something intelligent happen.
Consider the humble case where you don't have a value yet because you haven't yet asked the server for that value. Suppose, now, that you want to display that value. Well, you want to let the user know that you've made a request, and you're waiting for a response before the real result can be displayed.
There are several things that could happen. The server could barf, in which case you should display a usable error message, where usable means that it gets the problem fixed quickly. The server could fail to respond in any reasonable time, which would bore the user and be grounds for the program to appologize. The user could get bored more quickly, and decide to cancel the request and work without it. After doing so, the user may later wish to restart the request in hopes of getting a quicker response, perhaps after plugging the network cable back in. And finally, the networking layer might report some other kind of error, which should be communicated (politely) to the user.
What we have here is a rather complex protocol for interaction among the user and various subsystems. Protocols veritably scream out for state machines. I want a state machine.
Now I'm a big fan of reusable program components. I figure that if a state machine is so generic an idea, then we should be able to program with them where it makes sense.
Javascript doesn't come with a built-in state machine system, but of course any competent computer scientist can create one with relative ease. In fact, he or she may easily create a profusion of different, reusable, unlikely-to-actually-be-reused state machine engines for each time that a problem arises which calls out for the idea of a finite state machine. There's a jillion ways to write a state machine, and they all take time.
So when do we get to the part where the magic happens?

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home