Tcl/Tk 8.5 Programming Cookbook Review

Packt Publishing contacted me with the offer to send me a copy of their newly released book on Tcl called "Tcl/Tk 8.5 Programming Cookbook" by Bert Wheeler if I would write a review of it. I accepted their invitation because I would love to be able to suggest a good and current book on Tcl for HomeVisionXL users who are interested in writing their own plug-ins.

In my years of using Tcl and interacting with the Tcl community I had not come across the name of the author of the book before, which of course doesn't have to be an indication of his level of experience with Tcl. Unfortunately there are a number of telltale remarks in the book that show that the author doesn't yet have a clear understanding of Tcl himself. So, instead of guiding the reader around some common misunderstandings that many beginners with Tcl have and explaining the reasons behind why things work as they do, he reinforces the misconceptions.

It sounds like he received some good advice from more experienced Tcl users that he didn't understand or that didn't really sink in. For example: He passes on the very useful advice to "always brace your expressions". Doing so prevents double substitution, which speeds things up and curbs security problems caused by code injection. However, in most examples in the book the author doesn't follow this advice himself. There is even an example in the book that is susceptible to code injection where the expression is not braced.

The book covers a quite random selection of Tcl and Tk commands by pretty much copy & pasting the manual page for the command, accompanied by a few lines of introduction and some example code. Several of these introductions contain inaccuracies. The code is sometimes buggy or misleading, and uses commands that are not covered in the book, so the reader will have to refer to the Tcl manual pages for those commands anyway.

The Tk part of the book is better than the Tcl part. The pack geometry manager is explained very well. On the other hand, any visual appearance that can be achieved with the pack geometry manager is also possible with the grid geometry manager. So in my opinion it might have been better to stick to one geometry manager and instead cover a common widget like the scrollbar, which is currently not mentioned in the book.

I don't like to give unfounded criticism, so I'll mention a few examples of the incorrect statements and misleading code:

According to the book, the append method of the "dict" command appends key/value pairs to a dictionary. In reality it appends data to the value of a dictionary member. Only when you specify a non-existing key, a new key/value pair will be added to the dictionary. But that is more of a side effect, not the primary function of the append method.

The example given for "string trim" mentions that [string trim "picture.gif " .gif] returns "picture". First of all, this is not true due to the space at the end of the input string. But assuming the aspiring Tcl programmer reading the book is able to figure out that the space is not supposed to be there, he will probably be surprised when trying the same command with "figure.png" and ending up with "". The book fails to make clear that not the string ".gif" is removed from either side of the string, but as many as possible of the characters ".", "f", "g", and "i".

The introduction to the "string length" command contains a complicated story about how the command doesn't return the number of characters in the string but the number of bytes used to represent the value contained within the variable in memory. This is completely wrong. The "string length" command actually does return the number of characters in the string. An additional mistake in this story is that the "string length" command takes a string as argument, not a variable.

All in all, the book contains too many errors and paints a confusing picture of Tcl. I would therefor not recommend it to the complete beginner in Tcl. For someone experienced enough in Tcl to be able to make the examples work despite the errors and typos, there is not enough new information that couldn't also easily be found in the Tcl manual pages. The only people that I feel could benefit from this book are those who are proficient in Tcl and want to get an introduction into Tk.