Book Review


Two C++Tutorials

reviewed by David Weber



Title: Practical C++ Programming
Author: Steve Oualline
Publisher: O'Reilly & Associates, Inc.
Release: August 1995, First Edition
Pages: 584
Price: US$ 29.95
ISBN: 1-56592-139-9

Title: C++ The Core Language
Authors: Gregory Satir and Doug Brown
Publisher: O'Reilly & Associates, Inc.
Release: October 1995, First Edition
Pages: 228
Price: US$ 19.95
ISBN: 1-56592-116-X

In the software professions reading is like breathing. Stopping can be dangerous to your health. So we spend our evenings inhaling book after book. Some are refreshing, some are stale, and we learn to discriminate by quickly thumbing through the pages while being jostled in a crowded bookstore aisle.

When a topic first appears on the horizon, the literature is scant, with magazines providing most of the information. As the topic evolves it produces at first a zephyr, and later a gale, of books. C++ has become a veritable hurricane. In a way, I am envious of today's new C++ programmers; my introduction to C++ was Stroustrup's The C++ Programming Language and a well-scribbled Zortech v1.2 compiler manual. Neither of these was a gentle introduction to the language. I wish I had had the wide selection of texts now available. On the other hand, I also feel relieved; picking the right book out of the hurricane is not an easy task.

Computer language books come in two major flavors: tutorials, for people who need to learn the language, and references, for people who need in-depth explanations of language features. C++ no longer has a definitive reference. The venerable ARM [1] is now out of date, but now that the standard is crystallizing, we can probably expect equivalents to be published. However, there are an abundance of C++ tutorials, including both of the books reviewed here. When I first glanced through them, I wondered why a single publishing house would release two tutorials on the same subject. Isn't this a form of self-competition? As I read the books, I found out why. They target distinctly different audiences.

A C++ tutorial can aim at one of three audiences: complete novices to C++ and to programming, those programmers making a transition from a different programming language, and those coming from C. Although the preface of Practical C++ Programming suggests that the book is written for both the novice and the experienced C programmer, it is really aimed at the beginning programmer. Fully 70% of the pages cover basic C subjects. In addition to language fundamentals, the book also touches on the entire software development process, including requirements, specification, design, coding, testing, debugging, release, and maintenance. Any of these subjects could fill a shelf with books.

My impression is that Practical C++ Programming would make an ideal entry-level college textbook. It gives a broad overview of the field that keeps the student looking at the forest instead of the trees, and it encourages a practical step-by-step development of C and C++ skills. My impression is reinforced by examples in the book highlighting GNU C++ and GNU gdb. Both of these Free Software Foundation products are a natural choice in budget-strapped college environments.

The book leaves out some C topics, such as internationalization and fancy pointer manipulation, and it skimps on the standard library. It also misses late-breaking C++ concepts, such as namespaces, run-time type identification, and new-style casts. The book gives short shrift to templates, exceptions, and multiple inheritance. But in a text for beginners this is probably a good idea.

Practical C++ Programming contains most of components we expect to find in a book. It has a table of contents, index, and glossary. It does not have a bibliography, an inexcusable oversight in a tutorial. The glossary is a refreshing and welcome inclusion, considering that much of a programming language is nomenclature. Once you learn the words you can associate them with the logical concepts. Unfortunately, the glossary could use some more depth, as it lacks basic words like constructor and destructor. The book includes exercises at the end of each chapter; sample questions are scattered throughout the text. The book provides detailed answers for the questions but no answers for the exercises.

Finally, Practical C++Programming has a clean layout, with very few technical or typographical errors. It stresses a safe, legible coding style and uses short clean programs to underscore ideas. If you are new to C/C++ or are shopping around for textbooks for your college class this would be a good book to consider.

The other tutorial in this review, C++ The Core Language, targets a different audience. This book assumes from page one that you are proficient in C, and it starts with a second, differing premise: The authors argue that C++ is too complicated for a single book. So they have carefully isolated a subset (core) of the language and concentrated on elucidating that. Not that they have totally ignored advanced issues; they have planted "Advanced Topic Boxes" in the text, which indicate parts of the language excluded from their subset. Using these boxes and the good bibliography you can later pursue the intricate details.

So what do the authors leave out? They skip multiple inheritance, exceptions, the subtleties of const, depth on operator overloading, recent C++ additions, and the C++ standard library. The rest of the language they cover well. Unlike Practical C++ Programming, this book makes no attempt to give an overview of programming discipline. Instead, it concentrates on helping you get your hands dirty in the language machinery.

The first chapters talk about C++ as a better C. And, in my opinion, it is. With stricter type requirements, type-safe linkage, and macros replaced by inline functions, C++ is a smart transition even if you never write a line of object-oriented code. The rest of the chapters cover objects. The discussion starts with abstraction, moves to encapsulation, then to hierarchies, and ends with polymorphism. Each topic builds on the previous using small snippets of C++ code to demonstrate the syntax and usage.

My only complaint with the code examples is their early introduction of pointers in classes. I think all C++ tutorials should be required by law to include a special page: At the top of this page would be a large icon of a chain saw. Underneath, in 24-point block type it should say, "Warning: The Software General of the United States has determined that putting pointers in C++ classes can be hazardous to your health unless you fully understand Constructors, Destructors, Copy Constructors, and Assignment Operators."

C++ The Core Language just touches on object-oriented design near the end of the book. Specifically, it covers is-a and has-a relationships and how they affect design choices between derivation and composition. This issue could use more illumination than provided by this book. The hardest part of C++ is not learning how to use the tools but learning when to use what tool. This is also the point where C++ differs most from C.

This book also includes a table contents and an index. (If you think it is trite to point this out, imagine a technical book without an index. They exist. Don't buy them — they will drive you mad.) This book has a good bibliography but no glossary. It also lacks exercises at the end of the chapters. Exercises are a valuable addition to any tutorial, as they reinforce what was just learned and point out where the ideas can go. For example, I think that the great strength of Knuth's epic The Art of Computer Programming series lies in his very complete exercises.

I have always felt that the same simple elegance that characterizes good programming should also be found in books about programming. C++ The Core Language typifies this by weighing in at only 228 pages and, nonetheless, completely covering its stated subject.

This is not a book for advanced C++ programmers, nor is it a book for a person without a C history. It is a good selection for someone making the move from C to C++.

Next time the nights are long, turn off the tube, whether Web or Linear, and pick up a good technical book. It will either put you safely to sleep or be the breath of fresh air you really need. o

Reference

[1] Margaret A. Ellis and Bjarne Stroustrup. The Annotated C++ Reference Manual (Addison-Wesley, 1990).

David Weber is yet another programming veteran living in the Rockies who reads more than he should. He still doesn't need glasses. You can reach him at 75267.1632@compuserve.com.