Tcl HomeTcl Home Hosted by
ActiveState

Google SiteSearch

Event Driven Programming

Dealing with asynchronous events — files become readable, data arrives on sockets, mouse clicks, timers going off etc. — is required of most long running programs, be they word processors or network servers. Dealing with these is straightforward in Tcl, especially compared with most languages, which treat these in a non-uniform manner or require add-on packages for them.

A Unified Model. A single event loop permeates everything in Tcl/Tk programs that deal with I/O. When things happen on files, sockets, the GUI, timers or other input sources, events fire and Tcl callbacks are invoked, simple as that.

You don't need threads to do basic asynchronous I/O (though Tcl has fantastic thread support), and you don't need add-on packages to get this functionality (e.g. Python's Twisted). With Tcl, it's all built-in, easy to understand, easy to debug, and handled consistently across the board.

Callbacks. Tcl's "everything is a string" model makes callbacks easy; any arbitrary Tcl command (by itself, a procedure call, or an object invocation) can be a callback. Because there's no rigid structure to fit into, base class you need to subclass from, etc., Tcl makes writing callbacks simple and more natural than in other languages. It's one of the reasons using Tk from Tcl "feels right".