|
Generic Programming and the STL: Using and Extending the C++ Standard Template Library
 |
Author: Matthew H. Austern List Price: $54.99 Our Price: Click to see the latest and low price ISBN: 0201309564 Publisher: Addison-Wesley Pub Co (13 October, 1998) Edition: Hardcover Sales Rank: 31,819 Average Customer Rating: 3.75 out of 5
|
Customer ReviewsRating: 4 out of 5 Good Book On the Design of STL As one of the few non-tutorial books on the design of STL, the book serves its purpose. It illustrates that the STL is built on top of concepts, a different kind of abstraction from the traditional OO. It also explains in details how this abstraction is applied through iterators, containers, and algorithms, as well as their STL way implementation in C++. However, this book has several weaknesses. With all my respects to the author, I think that not enough is devoted to illustrate the big picture of how the STL uses these abstractions. For example, after explaining the iterators and containers, the book doesn't explain how the iterators serve as a bridge between generic algorithms and containers - the abstraction of iterators makes it possible to write generic algorithms without the knowledge of the type of the container, and vice versa. On the practical side, I think that while the book spend too much space on a complete reference manual to STL, not enough is spent on discussing the practical issues of extending and using STL such as making a non-trivial custom container or a custom memory allocator. Rating: 4 out of 5 Pretty good job The language C++ cannot be thought of as a mere extension to the C language. It supports object-oriented programming, and even more importantly, the generic programming paradigm. This book gives an overview of how C++ fits into the generic programming paradigm, and the author does a decent job of explaining how this is done. Anyone familiar with C++ and the Standard Template Library should have no problem following the dialog in the book. The approach taken by generic programming can be very abstract, but it is extremely powerful, and one that allows generality and economy of thought in programming. After a brief summary of the STL in chapter 1, the author moves on to studying linear search and iterators in chapter 2. The author stresses the need to design algorithms that are independent of the data structures they operate on. The discussion sets up the terminology and concepts for later chapters on function objects and containers in later chapters. The author introduces the idea of a concept, which is essentially a collection of type requirements, types, and valid programs. Readers with a background in mathematical logic are referred to the references for a discussion of the connection between concepts and the theory of many-sorted algebras. Iterators are introduced as five different types of concepts, these all serving as a generalization of pointers. The five kinds of iterator concepts are discussed in detail in the chapter. These concepts do have properties in common, and this leads the author to consider refinements of concepts. In addition, the different iterator concepts allow the author to classify generic algorithms according to the iterator concepts it uses. The discussion of iterators is continued in the next chapter, where iterator traits and associated types are discussed. The idea of an iterator value type is introduced as the object type the iterator points to. The author introduces, interestingly, a generalization of the type overloading capability of C++ to concept overloading, and he shows in detail how to emulate concept overloading in C++ . Function objects, which I consider one of the most powerful and useful concepts in generic programming, are discussed in chapter 4. Function objects are introduced as entities that can parameterize any kind of operation, and the author gives good arguments to show that every algorithm can be generalized by abstracting some part of its behavior as a function object. The associated types of a function object are the types of its arguments and return values. The composition of functions, so familiar in elementary mathematics, is here generalized to function objects via function object adaptors. Thus one can view function objects as entities behaving as expected in a mathematical sense. Containers are then introduced in chapter 5, essentially as generalizations of arrays, and the author stresses that the elements of a container are actual objects and not addresses. This "value semantics" of containers is shown to be a useful strategy by the author. The next part of the book begins an overview of generic programming concepts that are applicable in general, and not just the STL. STL though is given as an example in the discussion, and this is somewhat disappointing given the emphasis on generality. But the author does outline with clarity the important constructions in generic programming, such as iterators, function objects, and containers. Therefore this part of the book does serve as a good reference manual. The next part is a reference manual on the algorithms and classes available in the STL. The discussion on memory management primitives is useful for it gives information on the algorithms used to manipulate uninitialized storage in order to implement containers. Nonmutating algorithms, which are used for operating on a range of iterators without changing the elements they point to, are given a good overview, as are mutating algorithms, which modify the values pointed to by a range of iterators. The discussion of the predefined function objects is also useful, as they implement most of the standard arithmetic operations, such as multiplication and addition, and the logical operations, such as AND and OR. In addition, the discussion of member function adaptors is useful since it shows the reader how to call member functions as function objects. A polymorphic function call will result if the member function is virtual, and this, the author states, is a link between generic programming and OO-programming in C++ The very important Vector class is discussed also, stressing its ability for automatic memory management. In my experience, the Vector class has been one of the most useful features of the STL. Rating: 3 out of 5 Poor value, unfortunately. Rightaway, I should say I don't discuss the quality of the book. It has everything I would like to have when I am programming and need to look up a function of the STL. This is why I give it three stars. But nowhere did I see the following criticism, so I have to voice it out.This book consists of two parts, part I, and part II and III (which I count as the second part, see below). Part I is an introduction to generic programming as used in the framework of the STL (79 pages). All that stuff, you're supposed to know if you use the STL. It's all about using the STL, the design, and extending it. Using the STL is described in lots of web pages, so the book does not provide much added value to this. Extending the STL is discussed all in all in about three pages. That was the part I was most interested it (I am developing a new course about generic programming). The second part, making up the remaining 430 or so of the book, are Part II (Ref Manual: Concepts) and Part III (Ref Manual: Algos and Classes). They have long been available straight from the SGI STL web pages, ... and you can also download them for browsing locally. This is a much more convenient (at least for me) way to look up the documentation. I didn't see that the book provided better examples, or different content than, the SGI's STL pages. This book will be useful if you are aware of all the things I said, but still would prefer to browse a book, or for off-line study. My goal was to see a discussion of how to use and extend the STL (as advertised in the title). I did not expect the Reference Manual (which I had already). I am most disappointed in this. The difference between User Manual and Reference Manual is best illustrated by the Stroustrup or Lippman-Lajoie (user manuals) and the C++ ISO Standard (reference manual). You should be aware of this difference before you buy this book, and decide if you want it print in 430 pages or in a web site.
Similar Products
· C++ Templates: The Complete Guide
· More Exceptional C++
· Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
· The C++ Standard Library : A Tutorial and Reference
· The C++ Programming Language (Special 3rd Edition)
|