April 22, 2003

Relaxed code

We need a pithy phrase akin to “code smell” for well-written, easily integrated code. For instance, one of the big changes in OpenInteract2 is how it’s managed. Previously you had the mammoth oi_manage script which did far, far too much. Now all the management tasks are broken into their own classes and obey a simple interface for execution (setup/run/tear_down) and declaring initialization requirements. Much easier to code and read, much easier to test.

One of the major tasks is creating a new site, and while running it I noticed the delay between executing the task and any feedback. This is one of those features that people really notice, so I gave some thought to introducing feedback during processing. Since I don't normally do event-driven programming (with progress bars and the like) I was stumped at first, but then I thought: observers. Duh!

Since all management tasks inherit from a single class (OpenInteract2::Manage), I stuck Class::Observable in its @ISA, sprinkled a few notify_observers() calls in the website creation tasks, then created an observer subroutine that gets added to the task from oi2_manage. Run the task: bingo.

Total time elapsed: about four minutes. And everything just worked. Sequences like this make me think I know what I'm doing.

Next: It's a rule, except when it's not
Previous: The tax blitz is coming!