From C to Tcl

Dr. Dobb's Journal February 1998

By Gerald L. Graef

Gerald is a programmer for Catalyst International. He can be contacted at ggraef@csd.uwm.edu.

Expert C Programming: Deep C Secrets
Peter van der Linden
Prentice Hall/Sunsoft Press, 1994
350 pp., $37.80
ISBN 0-131-77429-8

Graphical Applications With Tcl and Tk
Eric F. Johnson
M&T Books, 1996
374 pp., $39.95
ISBN 1-558-51471-6

For working C programmers, bookstores generally have two types of C books -- the "too simple" and the reference manual. Few books even pretend to take on advanced C programming. One that does, however, is Expert C Programming: Deep C Secrets, by Peter van der Linden. It's not a tutorial, and it's not a reference. It's stuff for experienced C programmers who know (or at least want to know) the difference between pointers and arrays.

You might expect a book on advanced C to be dull. After all, how much humor is contained in the format of an ELF binary? But Expert C Programming is the perfect counter to this thesis. van der Linden has written a book filled with essential C lore and anecdotes that can only come from long experience, yet he presents it in a way that makes the book hard to put down even for nonprogrammers!

In writing an advanced text, van der Linden does not need to cover C in its entirety, but is free to pick and choose those areas that he has seen at the core of programming problems. This is not a book about programming theory -- it is about getting C to do what you want, often in ways you never knew were possible.

The content of Expert C Programming is well summarized by the chapter titles (with a few comments added for clarity):

Scattered throughout the book are special sections to enlighten the main text. "Handy Heuristic" gives ideas and guidelines gleaned from the author's experience. Examples, explanations, and further tidbits are featured in "Software Dogma." Finally, "Programming Challenge" offers a chance to apply the ideas at hand (the solutions are provided). The appendix is the ultimate programming challenge: navigating job interviews. To select gifted and experienced programmers, many companies schedule interviews with their best technical people. Questions are often subtle, sometimes simple. I suspect that, in these days of too few programmers, companies go a little easier on their applicants: I certainly have never faced interview questions of this sort. But thanks to this book, I'm ready for them.

It's hard to imagine a C programmer who won't get something out of this book. But this book would also be outstanding for the junior programmer who is looking beyond routine C: The programmer who is not a nine-to-fiver or a manager wanna-be, but the future guru who still needs a little help making the transition from basic text to dissecting the ISO documents. Many programmers go through their careers without the kind of knowledge contained in this book, and for the most part, they get by. You can do C this way. But you can't do it well. If you do C, take a look at this book.

Moving on to Tcl

In the past few years, scripting languages have become an important part of programming life. Traditional shell scripts, while useful, are limited in function and flexibility. Perl, Python, Tcl/Tk, and other scripting languages have risen to fill the void. Perl's access to operating-system functions is matched only by C. But in the arena of graphical interfaces, only two choices are manifest -- traditional languages and Tcl/Tk. More than a scripting choice, Tcl/Tk lets you do what no other language (save Java) can do -- create programs that can be independent of both graphical hardware and operating systems.

Tcl (short for "Tool Command Language") was developed by John Ousterhout in 1988 as a simple, yet easily expandable scripting language. The Tk "toolkit" was added later to provide graphical capability. Tcl/Tk is also a library that can be used with other languages -- basically, a program generates Tcl/Tk code and passes it to the Tcl/Tk interpreter.

Several books about Tcl exist, though continual development quickly dates them. The ultimate reference is, therefore, the man pages. On the other hand, books can shine as tutorials and introductions. A good example of one such book is Graphical Applications with Tcl/Tk, by Eric F. Johnson.

Graphical Applications with Tcl/Tk begins at a measured pace to ensure you understand the basic tenets of Tcl. In fact, Chapter 1 covers nothing more than the obligatory "hello world" program (with its own window and exit button). Chapter 2 describes the basic functioning of Tcl: syntax, variables, and expressions. The next five chapters cover "Interacting with the User," "Menus," "Text Editing," "Lists, Files, and Directories," and "Dialog Windows." Following this introduction to Tcl basics, several "Advanced Applications" are covered, including debugging, images, running commands from Tcl (and Tcl from other applications), and extending Tcl. The coverage of the language is sparse at best, but it is sufficient for the central purpose of learning to use the man pages and to create platform-independent graphical programs. As the owner of a schizophrenic PC (Windows 95 and Linux, each with a Macintosh emulator), I find it very satisfying to be able to write a script for X Windows, then run it on Windows -- and then run it on a Macintosh!

Graphical Applications in Tcl/Tk comes with a CD-ROM containing binaries for Windows (95/NT/3.1), and sources that can be compiled on most UNIX systems and on Windows. Also on the CD-ROM are examples from the book and various packages from around the world. I had no problem installing the binaries for Windows 95, nor with compiling the source on Linux.

Still, if you are looking for a comprehensive reference, go to the man pages. If you are an experienced script writer and want to dive into Tcl/Tk full force, other books or even web-based tutorials offer better options for getting a fast start. But for anyone else looking to learn Tcl/Tk -- and especially platform-independent graphical interfaces -- this is a book worth checking out.

DDJ


Copyright © 1998, Dr. Dobb's Journal