Kudos to Andrew Krause and Apress for publishing a book about GTK+ 2. Krause’s Foundations of GTK+ Development is the best book and really the only book to buy if you want to learn GTK+ 2. All the other available books which I could find seem to be out-dated and focused on GTK+ 1.2.
A couple years ago, I struggled through Havoc Pennington’s on-line-book for GNOME and GTK+ programming, and gave up in total frustration. In contrast, Andrew Krause’s book is extremely clear and walks you through the basics step by step, with exercises at the end of each chapter to make sure that you really learned each step. The book is an excellent how-to guide to using GTK+. If you stick with the book and faithfully do each exercise, you will learn GTK+.
Even for advanced GTK+ programmers, the book is useful as a reference manual, since it covers a lot of widgets that aren’t commonly used and has excellent appendixes covering properties, signals and other elements of the GTK+ widgets. The only drawback for me is the lack of information in the appendixes about how each widget is derived. It would be helpful to know the parentage of each widget in order to know which properties are available to the child widgets.
The prose in the book is not very inspiring, but this is a programmer’s manual, not a work of literature.
Where the book falls short is in the first two chapters which introduce GTK+ and explain the basics of getting a window to appear on your screen. The book makes little attempt to give a general overview of how GTK+ works and the general concepts of GTK. Generally I appreciate a hands-on how-to, but in this case, I was left very frustrated by my lack of understanding of the basic concepts. Once you get past the first couple chapters, the book is excellent, but Krause really should provide a basic overview of how GTK+ works and the general hierarchy of objects and widgets, before jumping into programming examples to get a basic window on your screen.
Here is what I think needs to be added to the book:
1. In chapter 1, there should be some discussion of the advantages and disadvantages of GTK+ and why you should use it or not use it. There should be some effort to compare it with Microsoft’s MFC, TrollTech’s Qt, Motif, WxWidgets and FLTK, so we know why it is worth struggling through the next 600 pages to learn GTK+.
2. The half page of history on GTK in the introductory chapter is downright uninformative and feels like an afterthought. The first chapter should have some discussion of how GTK+ evolved as the alternative to commercial and more proprietary Qt and why it attracted the support of free software hackers and why Red Hat and Novell have chosen to support its development.
3. In reading Krause’s book, you never get the sense that GTK+ is developed by a community and what that implies. (Poor documentation, cool ideas, people who believe in the ideology of free software, etc.) A little comment about how to get involved with the GTK+ community of developers would also be nice.
4. How to use GTK in Windows or any other platform other than GNU/Linux. It is surprising that Krause doesn’t discuss cross-platform programming considering the fact that the cover of the book describes GTK+ as “one of the world’s most powerful cross-platform toolkits”. Only in Chapter 6 when discussing some of the GLib functions does Krause touch on difference between Windows and UNIX-like systems. Many GTK+ programmers want to know how to at least compile their programs in Windows, and this book won’t give them a hint what to do or what to install. There should be a chapter at the end or a least an appendix discussing how to use GTK+ on different platforms and with languages other than C.
5. Krause provides good instructions on how to download and compile GTK+ on your computer, but his instructions on how to download and install GTK+ from repositories is very vague, despite the fact that the vast majority of programmers are going to use the latter method. Of course you can’t cover every distribution, but I’d like to see instructions for at least the two major families of GNU/Linux such as:
In a standard installation of Debian 4.0, GTK+ can be installed with:
apt-get install ...
In a standard installation of Fedora Core 8, GTK+ can be installed with:
6. The book needs a chapter after the first chapter which gives an overview of how GTK+ works and the basic concepts in GTK+. At the very least, Krause needs to include a conceptual graphic which shows how GTK+ interacts with the underlying system (X-Windows, MS Windows, etc.). A graphic of the hierarchy of GTK objects and widgets would also help clarify how GTK+ is organized. Finally an explanation of how GDK relates to GTK+ would have clarified the general layout of GTK+.
7. The book needs some discussion of how type-casting between different types of objects and widgets works in GTK+. Krause declares most of the elements as general GtkWidgets in his programming examples, and then type-casts them as other derived widgets when making GTK+ function calls. He should explain why this is a good programming strategy. At the very least, Krause should explain that he is doing type-casting between GtkWidgets, because the beginning programmer won’t understand what the function GTK_WINDOW() does.
8. The explanation of events is very vague. You have to go to the appendix to learn that returning TRUE in the function that handles an event causes it to stop and not be passed on the system to be handled by default. This is counter-intuitive and needs to be explained.
9. Krause provides occasional comments about how to create interfaces which function with multiple languages (for example his advice to not use tables and fixed sized widgets), but he doesn’t bother explaining how to use gettext, which in my opinion is necessary knowledge if writing an application.
Of course, including all this extra material would make a long book longer, but Cross-Platform GUI Programming with wxWidgets by Julian Smart et al. does a good job of explicating most of these points without getting bogged down. In particular Smart et al. do an excellent job of providing a general overview of wxWidgets in the first chapter, which Krause should use as a model.
Despite all my criticisms, I still recommend Krause’s book as a the book to buy to learn GTK+. It will teach you what you need to know so you can get your hands dirty and actually write GTK+ programs. For a list price of $50, the book is overpriced in my opinion, but it seems that $50 has become the standard list price for good programming books nowadays. Publishers have upped their prices with the expectation that online sellers such as Amazon will simply discount their books down to $30-$35. If you happen to be a poor sap who buys ethically from a bricks-and-mortar bookstore you get screwed. Coming from the Andes where I pay $37 a month for a month’s rent, I really had to scratch my head and wonder if Krause’s book could fit into my modicum of a budget. (Of course, my Bolivian friends have figured out how to get around inflated Western prices by illegally downloading all their programing books from the internet.) Even having paid the full list price, I’m still happy to report that Foundations of GTK+ Development is worth buying if you are wont to brave the hazards of desktop application programming.