Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

The Tcl/Tk and Python Scripting Environments


Oct98: Programmer's Bookshelf

Sean, chief technical officer and cofounder of Digitome Electronic Publishing (http://www.digitome.com/), is a member of the World Wide Web Consortium's XML Special Interest Group and the Python Software Activity (PSA). He is the author of XML by Example: Building E-Commerce Applications (Prentice Hall, 1998). Sean can be reached at [email protected].


Effective Tcl/Tk Programming
Mark Harrison and Michael J. McLennan
Addison-Wesley, 1998
400 pp., $39.95
ISBN 0-201-63474-0

Internet Programming with Python
Aaron Watters, Guido van Rossum, and James C. Ahlstrom
M&T Books, 1996
450 pp., $34.95
ISBN 1-55851-484-8

When enough time has passed for someone to write a history of programming in the 20th century, one curious fact will stand out -- the most influential programming languages tend to go through a gestation period in which word of mouth and Internet FAQs are more important means of spreading the news than published books.

The solitary book, or at most, pair of books, devoted to teaching such languages often becomes a veritable "bible" to its community: shared, dog-eared, and tattered, read, reread, and revered by the faithful. Over time, with the slow, sure confidence of continental drift, more books covering such languages appear until a mainstream computing technology is born.

The two best examples of these bibles are instantly recognizable by their pet names -- K&R (The C Programming Language, by Brian Kernighan and Dennis Ritchie, Prentice Hall, 1988) and The Camel Book (Programming Perl, Second Edition, by Tom Christiansen, Randal L. Schwartz, and Larry Wall, O'Reilly, 1996).

To this shelf of fame I would like to posit the addition of two new volumes -- the "Atomic Snake" and "Sunset Paintbrush" books. Okay, so these pet names are mine and are unlikely to reach the status of industry vernacular. The former is my pet name for Internet Programming with Python by Aaron Watters, Guido van Rossum, and James C. Ahlstrom. The latter refers to Effective Tcl/Tk Programming by Mark Harrison and Michael McLennan. A quick look at the book covers explains how I arrived at these names.

A splash of sunset-colored paint streaking across its cover immediately establishes the lineage of Harrison and McLennan's Effective Tcl/Tk Programming. The same splash is on the cover of the original Tcl/Tk book -- Tcl and the Tk Toolkit by John K. Ousterhout, the father of Tcl/Tk. (Both books are part of the Addison-Wesley Professional Computing Series edited by Brian Kernighan, the "K" in K&R.)

Harrison and McLennan's book picks up where Ousterhout's leaves off. It assumes a working knowledge of Tcl/Tk and a desire to learn how to build bigger applications that go beyond the traditional textbook examples into the realm of fully functional applications.

The presentation is snappy, pragmatic, and purposeful. The book starts with the development of a small sketchpad application that shows what can be achieved with a paltry number of lines of Tcl/Tk. Heck, I have C++ files with more #include lines that that! (I wonder if the authors waded through the tons of MFC/C++ made famous by the Scribble example application of Visual C++?)

The authors are experienced Tcl/Tk developers. This experience is put to good use as they elucidate often misunderstood components of Tcl/Tk such as the packer, bind mechanism, and full capabilities of the canvas widget. On the way through this material, you can build a tabbed dialog box, do some animation, build a progress gauge, color editor, powerful calendar, text editor, and tree control.

By the time you have covered the material on driving other applications and network programming, the scene is set for the case study that is an important part of the book. "The Electric Secretary" is a powerful multiuser scheduling/calendar program that combines many of the concepts covered in a useful and realistic application.

If your appetite holds out you can proceed from here to a dessert of Tcl/Tk library creation and application distribution techniques. For coffee you can see how to adapt the Electric Secretary application for use within a web browser (a Tcllet!) using the Tcl/Tk plug-in at http://www.sunscript.com/products/ plugin.html.

If you are teetering on the brink of purchasing Effective Tcl/Tk Programming, you might want to download the Tcl/Tk plug-in and examine the Electric Secretary application at http://www.aw.com/cp/ efftcl/elplugin.html. Also, all the software developed in the book can be downloaded from http://www.awl.com/cseng/books/efftcl/. This, combined with the Electric Secretary application, allows you to get a good idea if this book is for you.

Interestingly, Harrison, in an interview at the Addison-Wesley web site (http://www2.awl.com/cseng/innovations/spring98/harrmclen.html), refers to the "drug dealer" theory of how to get people hooked on developing Tcl/Tk. The first application costs little or nothing and then users are hooked. It is difficult to go back to writing thousands of lines of C/C++ code when a few hundred lines of Tcl/Tk script will do the same job in a fraction of the development time!

This path from C/C++ to Tcl/Tk is perhaps the most worn but there are others. Some programmers (myself included) encounter Tcl via travels in other scripting languages that provide interfaces to the Tk system for building cross-platform GUIs. Python (http://www .python.org/) is one such programming language. I am glad to report that it is in keeping with my pet theory about influential programming languages as only two books are currently available devoted to Python.

Python is an easy-to-learn, object-oriented, high-level language with powerful built-in types and a rich set of ready-to-go libraries. It is easily extensible in C or C++ and is freely available even for use in commercial applications. Although Internet Programming with Python, dates from 1996, it is somewhat ahead of its time as it provides detailed and useful information about advanced Internet programming techniques.

The first subhead of Chapter 1 sums up the chapter rather well: "Python Gets the Job Done." The chapter presents all the positive aspects of the Python language and, with admirable candor, also lists the things that Python is not well suited for. These include the intensive bit twiddling frequently required in data compression and graphics algorithms. Then, of course, there are areas where execution speed and memory footprint are paramount, such as with device drivers. Chapter 1 ends with the obligatory print 'hello world' application that, in Python, is written precisely as it appears here. Chapter 2 gets down to details with a tour of Python's structure in terms of syntax, keywords, statements, data types, and built-in object types.

One of the most striking things about Python is its orthoganalty with respect to built-in operators. For example, in Python, any type classed as a "sequence type" has built-in indexing, slicing, set membership, and iterator functionality. These are explained through Chapter 4. Chapters 5 and 6 cover the syntactic details and tricks of the trade. Of these, Chapter 6 in particular needs to be read twice, as Python pulls numerous interesting tricks under the hood!

The first half of the book covers the core concepts of Python. The second half is Internet programming all the way. The prescience of this book stands out in Chapter 7, which covers the on-the-fly generation of HTML -- a topic of considerable interest in this age of HTML tag-creep and web-site expansion. Also covered in detail are HTML parsing, advanced CGI scripting techniques, and TCP/IP socket protocol programming. By the time you get through this, you might want to look through the source code for Grail -- a web browser written entirely in Python by Python's creator (and coauthor of this book, Guido van Rossum). The book also addresses techniques for extending and embedding Python. The latter is illustrated by embedding Python under a Netscape Server using NSAPI.

As mentioned earlier, Python has an interface to Tk. The interface module known as tkinter has been put to great use in the Grail web browser. It is also to be seen strutting its stuff in the Red Hat Linux distribution where it has been used to create the system control panel. As you would expect, Grail is particularly good at running applets written in Python. These run in a restricted mode very similar to the Java Sandbox as well as the Tcl sandbox enforced by the Tcl/Tk web browser plug-in.

Which brings me back to Tcl/Tk. On the face of it, the similarities between the capabilities of Tcl/Tk and Python would seem to lead programmers toward making a one-or-the-other choice. Interestingly, in practice, this does not seem to be the case. I know of a number of applications that are termed "Python applications" yet are partly implemented in Tcl. Come to think of it, I have a Python program partly written in Perl.

Perhaps this too will emerge as a curious fact recorded in the history of 20th-century programming languages. Languages such as Python and Tcl began life as "glue languages" intended to allow applications/modules written in compiled languages such as C to be joined together. It would seem that an increasing amount of glue is being used to glue together glue languages!

DDJ


Copyright © 1998, Dr. Dobb's Journal

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.