MARCH 2007 (Vol. 8, No. 3) p. 5 1541-4922/07/$26.00 © 2007 IEEE Published by the IEEE Computer Society Twisted in Knots
A review of Twisted Network Programming Essentials by Abe Fettig Twisted Network Programming Essentials Abe Fettig 213 pages US$29.95 O'Reilly, 2005 ISBN: 0-596-10032-9 As a tool for rapid prototyping of small applications, Python has few rivals among programming languages. Python is simple and easy to use for beginners to learn yet sufficiently powerful for experienced software developers. Python interpreters written in C, Java, and .NET integrate Python with those environments, and the mass of Python libraries and "Pythonic" bindings for native libraries makes HTTP clients, in-memory databases, and many other tools easily accessible to even the most novice user. Unfortunately, for most complex applications the language has proved less fit. The Web application space is a case in point. Python has suffered from a distinct lack of high-quality Web servers and Web application frameworks. In contrast, such languages as JSP, ASP, and PHP enjoy the support of companies that specifically target the Web market and set the standard for tools in these languages. Python remains a minor player in this market despite the maturity of the language (Python was invented in 1991) and the existence of a plethora of Python Web environments, such as Zope, and an Apache module, mod_python. Twisted Enter Twisted (http://twistedmatrix.com). Twisted is a Python framework for event-driven network programming. It supports a wide range of network protocols, including POP3, IMAP, HTTP, SSL, and others. In some respects Twisted is an ideal platform for developing Web applications: it's event-driven for scalability, it includes an extensive protocol library, and it's open source. Twisted Networked Programming Essentials by Abe Fettig introduces and documents the core of the Twisted framework, from the basics of the event model to writing your own SSH server. The book includes chapters on client and server development for mail protocols like SMTP and IMAP, Web basics such as HTTP GETs and POSTs, and Web services using SOAP and XML-RPC. The text is example-driven, with detailed explanations of the code samples, which are presented in their entirety. Each chapter focuses on a different feature, but the style throughout is consistent. The catch As project founder Matthew Lefkowitz relates in the preface to Twisted Networked Programming Essentials, Twisted was originally devised as an asynchronous networking subsystem for an online game. At some point in its development, however, the framework eclipsed the game entirely and became an end in itself. Unfortunately for the naive Python programmer, the resulting absence of real requirements for Twisted is all too evident. Even a casual perusal of the Twisted source shows that the developers' chief goal was writing their own framework. The Twisted documentation still describes numerous long-extant components as "basic" and "rudamentary" [sic] while an essential reworking of the Web subframework languishes "under active development" in the source repository. To its credit, Twisted does distinguish itself from similar products in that it's completely asynchronous, employing events and continuations instead of threads. But that doesn't make the framework more reliable or fully featured. Just the opposite: in the excitement of rediscovering event-driven programming, the developers seem to have forgotten small details like persistent HTTP client connections, rendering nearly useless the easy-to-prototype Web client interface that the book touts. The same criticism applies to other components of the framework, such as the authentication classes, which are clumsy at best. Other parts, such as instant messaging clients, seem to have been designed for someone's limited deployment and included in the framework by default or simply to pile on one more feature. Conclusion It's difficult to separate these concerns from the merits of Twisted Network Programming Essentials. The book does include some information and code not readily available in the rather elusive Twisted documentation, such as an example IMAP server. Fortunately for the reader, the helpful examples in each chapter aren't obscured by Fettig's pedantic writing style and redundant explanations. By and large, however, it would be simpler for the reader to download the example code and then read the Twisted documentation for basics—not that anyone should be encouraged to go that far. Minor Gordon is a PhD student at the University of Cambridge Computer Laboratory, where he does research into the design of event-driven Web servers.
| |||||||||||||||||||||||||||||||||||||||||