Book Review : Beginning Linux Programming (Second Edition)
Richard Stones
and Neil Matthew, Wrox Press. £28.99
(Foreword by Alan
Cox)
21 Chapters and
4 Appendices in 839 Pages.
Contents
Chapters
1 Getting Started
2 Shell Programming
3 Working With Files
4 The UNIX Environment
5 Terminals
6 Curses
7 Data Management
8 Development Tools
9 Debugging
10 Processes and Signals
11 POSIX Threads
12 Inter-process Communication: Pipes
13 Semaphores, Message Queues and Shared Memory
14 Sockets
15 TCL: Tool Command Language
16 Programming for X
17 Programming GNOME Using GTK+
18 The Perl Programming Language
19 Programming for the Internet: HTML
20 Internet Programming 2: CGI
21 Device Drivers
Appendices
A Portability
B FSF and the GNU Project
C Internet Resources
D Bibliography
Synopsis
Quite obviously, this book is aimed at those wishing to write programs for their Linux system. Amazingly, though, the amount of prior knowledge that this book expects of the reader is fairly minimal: obviously, programming experience is always going to be a help, but even the most basic UNIX-isms are explained. The idiosyncrasies of the Linux system are pointed out at all times, making the book really quite easy to get into. Even if you have no programming experience, you will be programming from the first few pages, and you will be understanding everything that you're doing - at no point do the authors make the common mistake of telling the reader to 'assume this works for now; we'll explain it later'.
There is no better book on the market, to the best of my knowledge, that covers general Linux programming in such detail. At twenty-one chapters, and below thirty pounds, this is really very good value-for-money for a book such as this. The coverage is extensive: everything from basic shell scripting and TCL programs to the most complex, hand-optimised device drivers are discussed. At the start of the book, you'll be learning the familiar 'Hello, world!' program - at the other end of the book you'll be diagnosing kernel oopsen / dumps by analysing the core, register and state dump of your CPU. And it doesn't miss a great deal inbetween! If I had some criticisms of the book, it would be that KDE programming is not covered; and Perl is skimped over a little bit, but at the end of the day, you have to stop a book at some point, and at over 800 pages it cannot be said that this is a small book. But apart from that, you can buy this book safe in the knowledge that not only will you quickly get up to speed with Linux programming, but you'll also be learning skills that are transferable to UNIX in general; be it *BSD, Solaris or IRIX.
Review
This book starts as it means to go on - with a foreword by Alan Cox. (For those not in the know, Alan is one of the primary developers of the Linux kernel, responsible for networking in particular. He is generally considered to be Linus' right-hand man) Although it cannot be said that Alan has had any great input into the book, it gives the tome an air of authenticity that wafts throughout - this is a real Linux book. It is clear that Alan has read the book, not only this second edition, but the first also. For a lot of Linux devotees, this will be reason enough to buy the book - it is unheard of for Alan to lend his name to an unworthy product. And without being presumptuous, this is no exception - this is a fine book.
This book covers a lot of topics. However, these can be divided up into a number of areas. The lingua franca throughout most of the book is, of course, C, and for those with a mortal fear of this language, do not be afraid: unlike a number of authors I can think of, these guys can actually write decent code. The primary aim of the book seems to be giving the reader a grounding in ANSI C, using the POSIX and X/Open specifications. What this means is, with a little tweaking, but often none at all, virtually 100% of the C programs within this book will traverse from platform to platform with ease: generally, just typing 'make' will compile them. This is especially true if the platform in question uses GNU tools (the free UNIX tools from the Free Software Foundation). Another side-effect of this style is that the majority of the code is well-written, and very clean.
Readers will be happy to know that by following the instructions in this book, they will be complying with the Linux 'Coding Style' guidelines, for the most part. Correct C-code formatting, ".. as shown to us by the prophets Kernighan & Ritchie" (to quote Linus Torvalds) is followed rigorously, except for the fact that indentations seem to be four characters, although this is probably for reasons of printing rather than anything else. Everyone knows, of course, the correct method of indentation is using the tab key. Those new to the language of C will quickly become proficient writers of good code, and this is to be applauded: I have seen so much poor code in my lifetime (people using two spaces to indent, for example. Linus correctly refers to these people as '.. heretics') that to see a book which promotes the correct methods is a refreshing change - it's like bad posture: there are so many people who go slouching around, if only they would sit up straight!!.
Another aspect of this book is the multiple programming languages introduced. Shell scripting is, quite obviously, a language of it's own, as is TCL, Perl, and to a lesser extent HTML (whether or not HTML can be considered a 'programming language' is something of a mute point). Some people may find it slightly off-putting that the authors introduce a number of different languages, when just C would usually do: certainly; there is very little in this book that could not be done with C rather than one of the other languages. However, I'm one of the people for whom 'it's the algorithm, stupid!' - i.e., the language doesn't matter, that is just te manner of expression, it's the idea that counts. And for me, this book works really well in this respect - languages don't get introduced for no reason; it's always to illustrate examples which (in real life) are generally expressed in these languages.
One of the recurring themes throughtout this book is the example of a CD database program. The idea behind this is to create a program suitable for the storage of a number of items of information for each CD, so that the database can be searched, etc. This program is implemented and re-implemented many times throughout the book, generally using different styles, techniques, toolkits or languages. This is an exceptionally good idea: at a glance, the reader is able to see how each language or toolkit is different from the ones they already know. The fundamental idea behind the code changes very little, so immediately the reader should know what the program is doing, and the (smaller) job of working out how it does what it does becomes a lot easier. I can't remember who said this, but paraphrasing, "Show me your program, and I will be confused. Show me your data structures, and I will understand". This is key: the reader knows what data is being stored, and how the program is supposed to interact with this data. These are the most important facts, by far and away, when trying to read someone else's code, and facilitates learning easily.
Most of this book is dedicated to writing simple programs, small utilities, useful little tools. However, there are a number of very powerful concepts that are introduced in this book. For starters, the whole concept of code maintainence is visited time and time again. The modern methods of storing code - CVS, for example - are introduced, and it there is no reaosn why after finishing this book the reader would not be able to go on and take on bigger projects than those described. A number of other very powerful ideas are introduced, some of which very early on. Files, the cornerstone on which UNIX is built, are constantly referred to, and early on it is apparent to the reader just how powerful the UNIX concept of a single file structure really is. Pipes are also comprehensively discussed, as these are common method for inter-process communication, as are sockets, which are also the concept upon which X Windows is built.
This whole book smells of authentic Linux. Granted, most examples in C (for instance) are fully ANSI - POSIX - X/Open compliant, but it always seems to be, unquestionnably, undeniably, Linux. This generally stems from a number of things - the preponderance of GNU tools used throughout the book, the emphasis on GNOME in the X programming section, the coding style, the whole slant of the book. Wherever Linux differs from normal UNIX, either by not supporting a particular function, or by extended a function, it is noted, and while this book makes no claim to be a general UNIX book I believe that after reading this book, 99.9% of the skills learnt will be transferable to other UNIX-type platforms (this will probably also apply, to a lesser extent, to BeOS and Windows NT, and other such systems which can use GNU tools and / or have POSIX compliancy layers). I really don't think there's a better book fo learning how to program on the Linux platform currently available.
Review by Alex Hudson