Tcl HomeTcl Home hosted by
ActiveState

Google SiteSearch

Event Driven Programming

Dealing with asynchronous activities —files become readable, data available on sockets, GUI actions, and more — is a pure joy in Tcl, especially compared with most languages, which treat these all differently 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".