or
Sign in to turn on 1-Click ordering.
Give this as a gift certificate
Express Checkout with PayPhrase
What's this? | Create PayPhrase
More Buying Choices
Have one to sell? Sell yours here
or
Get a $13.25 Amazon.com Gift Card
Modern C++ Design: Generic Programming and Design Patterns Applied
 
 
Tell the Publisher!
I’d like to read this book on Kindle

Don’t have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Modern C++ Design: Generic Programming and Design Patterns Applied [Paperback]

Andrei Alexandrescu (Author)
4.4 out of 5 stars  See all reviews (70 customer reviews)

List Price: $59.99
Price: $48.45 & this item ships for FREE with Super Saver Shipping. Details
You Save: $11.54 (19%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.
Want it delivered Tuesday, August 3? Choose One-Day Shipping at checkout. Details
31 new from $36.44 21 used from $14.59

Frequently Bought Together

Customers buy this book with Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition) by Scott Meyers$40.74 

Modern C++ Design: Generic Programming and Design Patterns Applied + Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)

Customers Who Bought This Item Also Bought


Editorial Reviews

Product Description

(Pearson Education) A text introducing the concept of generic components within all C++ language. Discusses issues that C++ developers deal with on a daily basis, including policy-based design for flexibility, partial template specialization, typelists, patterns, and multi-method engineers. Softcover. DLC: C++ (Computer program language)

From the Inside Flap

You might be holding this book in a bookstore, asking yourself whether you should buy it. Or maybe you are in your employers library, wondering whether you should invest time in reading it. I know you dont have time, so Ill cut to the chase. If you have ever asked yourself how to write higher-level programs in C++, how to cope with the avalanche of irrelevant details that plague even the cleanest design, or how to build reusable components that you dont have to hack into each time you take them to your next application, then this book is for you.

Imagine the following scenario. You come from a design meeting with a couple of printed diagrams, scribbled with your annotations. Okay, the event type passed between these objects is not char anymore; its int. You change one line of code. The smart pointers to Widget are too slow; they should go unchecked. You change one line of code. The object factory needs to support the new Gadget class just added by another department. You change one line of code.

You changed the design. Compile. Link. Done.

Well, there is something wrong with this scenario, isnt there? A much more likely scenario is this: You come from the meeting in a hurry because you have a pile of work to do. You fire a global search. You perform surgery on code. You add code. You introduce bugs. You remove the bugs . . . thats the way a programmers job is, right? Although this book cannot possibly promise you the first scenario, it is nonetheless a resolute step in that direction. It tries to present C++ as a newly discovered language for software architects.

Traditionally, code is the most detailed and intricate aspect of a software system. Historically, in spite of various levels of language support for design methodologies (such as object orientation), a significant gap persisted between the blueprints of a program and its code because the code must take care of the ultimate details of the implementation and of many ancillary tasks. The intent of the design is, more often than not, dissolved in a sea of quirks.

This book presents a collection of reusable design artifacts, called generic components, together with the techniques that make them possible. These generic components bring their users the well-known benefits of libraries, but in the broader space of system architecture. The coding techniques and the implementations provided focus on tasks and issues that traditionally fall in the area of design, activities usually done before coding. Because of their high level, generic components make it possible to map intricate architectures to code in unusually expressive, terse, and easy-to-maintain ways.

Three elements are reunited here: design patterns, generic programming, and C++. These elements are combined to achieve a very high rate of reuse, both horizontally and vertically. On the horizontal dimension, a small amount of library code implements a combinatorialand essentially open-endednumber of structures and behaviors. On the vertical dimension, the generality of these components makes them applicable to a vast range of programs.

This book owes much to design patterns, powerful solutions to ever-recurring problems in object-oriented development. Design patterns are distilled pieces of good designrecipes for sound, reusable solutions to problems that can be encountered in manycontexts. Design patterns concentrate on providing a suggestive lexicon for designs to be conveyed. They describe the problem, a time-proven solution with its variants, and the consequences of choosing each variant of that solution. Design patterns go above and beyond anything a programming language, no matter how advanced, could possibly express. By following and combining certain design patterns, the components presented in this book tend to address a large category of concrete problems.

Generic programming is a paradigm that focuses on abstracting types to a narrow collection of functional requirements and on implementing algorithms in terms of these requirements. Because algorithms define a strict and narrow interface to the types they operate on, the same algorithm can be used against a wide collection of types. The implementations in this book use generic programming techniques to achieve a minimal commitment to specificity, extraordinary terseness, and efficiency that rivals carefully handcrafted code.

C++ is the only implementation tool used in this book. You will not find in this book code that implements nifty windowing systems, complex networking libraries, or clever logging mechanisms. Instead, you will find the fundamental components that make it easy to implement all of the above, and much more. C++ has the breadth necessary to make this possible. Its underlying C memory model ensures raw performance, its support for polymorphism enables object-oriented techniques, and its templates unleash an incredible code generation machine. Templates pervade all the code in the book because they allow close cooperation between the user and the library. The user of the library literally controls he way code is generated, in ways constrained by the library. The role of a generic component library is to allow user-specified types and behaviors to be combined with generic components in a sound design. Because of the static nature of the technique used, errors in mixing and matching the appropriate pieces are usually caught during compile time.

This books manifest intent is to create generic componentspreimplemented pieces of design whose main characteristics are flexibility, versatility, and ease of use. Generic components do not form a framework. In fact, their approach is complementarywhereas a framework defines interdependent classes to foster a specific object model, generic components are lightweight design artifacts that are independent of each other, yet can be mixed and matched freely. They can be of great help in implementing frameworks.

Audience

The intended audience of this book falls into two main categories. The first category is that of experienced C++ programmers who want to master the most modern library writing techniques. The book presents new, powerful C++ idioms that have surprising capabilities, some of which werent even thought possible. These idioms are of great help in writing high-level libraries. Intermediate C++ programmers who want to go a step further will certainly find the book useful, too, especially if they invest a bit of perseverance. Although pretty hard-core C++ code is sometimes presented, it is thoroughly explained.

The second category consists of busy programmers who need to get the job done without undergoing a steep learning investment. They can skim the most intricate details of implementation and concentrate on using the provided library. Each chapter has an introductory explanation and ends with a Quick Facts section. Programmers will find these features a useful reference in understanding and using the components. The components can be understood in isolation, are very powerful yet safe, and are a joy to use.

You need to have a solid working experience with C++ and, above all, the desire to learn more. A degree of familiarity with templates and the Standard Template Library (STL) is desirable.

Having an acquaintance with design patterns (Gamma et al. 1995) is recommended but not mandatory. The patterns and idioms applied in the book are described in detail. However, this book is not a pattern bookit does not attempt to treat patterns in full generality. Because patterns are presented from the pragmatic standpoint of a library writer, even readers interested mostly in patterns may find the perspective refreshing, if constrained.

Loki

The book describes an actual C++ library called Loki. Loki is the god of wit and mischief in Norse mythology, and the authors hope is that the librarys originality and flexibility will remind readers of the playful Norse god. All the elements of the library live in the namespace Loki. The namespace is not mentioned in the coding examples because it would have unnecessarily increased indentation and the size of the examples. Loki is freely available; you can download it from awl/cseng/titles/0-201-70431-5.

Except for its threading part, Loki is written exclusively in standard C++. This, alas, means that many current compilers cannot cope with parts of it. I implemented and tested Loki using Metrowerks CodeWarrior Pro 6.0 and Comeau C++ 4.2.38, both on Windows. It is likely that KAI C++ wouldnt have any problem with the code, either. As vendors release new, better compiler versions, you will be able to exploit everything Loki has to offer.

Lokis code and the code samples presented throughout the book use a popular coding standard originated by Herb Sutter. Im sure you will pick it up easily. In a nutshell,

Classes, functions, and enumerated types look LikeThis.

Variables and enumerated values look likeThis.

Member variables look likeThis_.

Template parameters are declared with class if they can be only a user-defined type, and with typename if they can also be a primitive type.


Product Details

  • Paperback: 352 pages
  • Publisher: Addison-Wesley Professional (February 23, 2001)
  • Language: English
  • ISBN-10: 0201704315
  • ISBN-13: 978-0201704310
  • Product Dimensions: 9.1 x 7.4 x 0.8 inches
  • Shipping Weight: 1.4 pounds (View shipping rates and policies)
  • Average Customer Review: 4.4 out of 5 stars  See all reviews (70 customer reviews)
  • Amazon Bestsellers Rank: #122,971 in Books (See Top 100 in Books)
    #67 in  Books > Computers & Internet > Microsoft > Development > C & C++ Windows Programming

More About the Author

Andrei Alexandrescu
Discover books, learn about writers, read author blogs, and more.

Visit Amazon's Andrei Alexandrescu Page

Look Inside This Book


What Do Customers Ultimately Buy After Viewing This Item?


Tags Customers Associate with This Product

 (What's this?)
Click on a tag to find related items, discussions, and people.
 
(6)
(3)
(2)

Your tags: Add your first tag
 

Sell a Digital Version of This Book in the Kindle Store

If you are a publisher or author and hold the digital rights to a book, you can sell a digital version of it in our Kindle Store. Learn more

 

Customer Reviews

70 Reviews
5 star:
 (48)
4 star:
 (10)
3 star:
 (7)
2 star:
 (2)
1 star:
 (3)
 
 
 
 
 
Average Customer Review
4.4 out of 5 stars (70 customer reviews)
 
 
 
 
Share your thoughts with other customers:
Most Helpful Customer Reviews

 
58 of 61 people found the following review helpful:
4.0 out of 5 stars template pathology, April 7, 2004
By A Customer
This review is from: Modern C++ Design: Generic Programming and Design Patterns Applied (Paperback)
Read this book and you may feel you've fallen down the hole into some sort of C++ Alice-in-Wonderland:

"Isn't it nifty just how much you can do with functions... that not only don't do anything but don't even really exist at all?" p.36

The title is a bit presumptuous; a more accurate title would be "Template Metaprogramming Stunts", since this book is primarily about tricks you can play with C++'s template mechanism.

The author does also make a go at proposing a new concept of "policy-based class design" -- by which he means using templates intead of multiple inheritance to create combinatorial mixtures of behavior. This is interesting, but seems hard to apply beyond the cliches he considers (ex: smart pointers), so his argument reads like a well-intended but parochial graduate thesis, with dutiful gestures of respect to his mentors (ex: Scot Myers) and limited range of real-world application.

The real meat of the book is his template techniques, which are ingenious -- if perverse, when seen from the standpoint of someone else trying to read and extend your code, or diagnose its arcane compiler errors. If you've ever had to work with other people on software, you may find his glib view of compiler errors disappointing. In many cases he relies on compiler errors to signal something more complex and semantic than the mere error would suggest. (If you're programmed much C++ you've surely experienced 10-line long STL template errors with a very simple underlying cause that is hard to discern from the error message. Learning to suss out what these mean is much of the sweat-work of learning C++.) I think this is simply that he's coming from the perspective that the interworkings of the language and the compiler are fascinating, and worth being a primary focus of study. But from the perspective of someone just tried to get your work done in the problem domain at hand, you may resent this attitude.

This book is best approached if you think C++ is really neat. Wheter you love C++ for its roccoco intricacy, or just see it as an evolutionary leaf node language full of botched misfeatures, you will find much here to confirm your opinion. I don't mean to belittle this book. There is real insight here: the idea of computing on types instead of values (to store the results of template-based computations) is a nifty idea. But it's worth keeping an eye on what problems you are really trying to solve, and which ones you may be creating.

Some telling quotes:

"Unfortunately, type_info's useful capabilities are packaged in a way that makes them unnecessarily hard to exploit." p.38

"For a variety of reasons, C++ is a language that leads its users sometimes to say, 'These are the smartest five lines of code I ever wrote.' Maybe it is its semantic richness or the ever-exciting (and surprising?) way its features interact." p.51

Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No


 
102 of 114 people found the following review helpful:
3.0 out of 5 stars Template Showboating, July 14, 2001
By "microtherion" (Sim City, CA (Somewhere in the Bay Area)) - See all my reviews
This review is from: Modern C++ Design: Generic Programming and Design Patterns Applied (Paperback)
While this is an interesting book, I'm not as unconditionally enthusiastic about it as most of the reviewers here seem to be. I felt that, as opposed to Scott Meyers' books and the original _Design Patterns_ book, many of the techniques presented in this book are the result of research into "elegant" solutions rather than experience with what really works in practical applications.

I really liked chapter 1 discussing policy-based class design, chapter 2 discussing various template techniques, chapter 6 discussing singleton implementation, anbd chapter 7 discussing smart pointers. Chapter 11 discussing multimethods, appears to be a good discussion of various alternatives but I'm not inclined to use multimethods anytime soon.

Chapter 3 about typelists is interesting, but after all the dazzling manipulations, all that typelists seem to be good for is generating class hierarchies, which I didn't find very compelling - it looks as if the typelists help to manage complexity that possibly wouldn't be there if the typelists hadn't been used in the first place.

Chapter 4 about small object allocation was of limited interest to me. The other chapters, 5 (Functors), 8 (Object Factories), 9 (Abstract Factory), and 10 (Visitor) offered fairly complex, template based solutions that to me did not look obviously superior to the straightforward manual implementations shown in _Design Patterns_.

Overall, a stimulating book, but one whose recipes will need careful evaluation before use.

Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No


 
32 of 34 people found the following review helpful:
5.0 out of 5 stars A significant and valuable book; strongly recommended., April 2, 2001
By Chris Newcombe (Seattle, USA) - See all my reviews
This review is from: Modern C++ Design: Generic Programming and Design Patterns Applied (Paperback)
I was waiting for this, and pestering bookstores for it for 2 weeks before it arrived. And it still exceeded my expectations. Note: The author was partly responsible for the C++ ScopeGuard library - an amazing, essential piece of code.

For any C++ engineers using reference counting (that'll be all of us, then), the amazingly configurable SmartPtr<> and the SmallObjectAllocator are instantly worth many times the price of the book. The deep, thorough analysis of Singletons, Functors, the Visitor pattern, Double-dispatch and Factories are all important chapters in their own right, with immediate use in real programs as well as educational value. The pervading concept of policy classes will undoubtedly influence your future approach to design, because the examples are all so elegant, compelling and downright useful.

But I think there is even more value in the longer term. This book takes a somewhat dizzying step into a new way of thinking, reminiscent of first encountering STL or GoF's Design Patterns. I feel sure that the concept of typelists is an important contribution to the direction of the language; a flexible, generic, *declarative* way of expressing relationships between abstractions. However, these techniques place such strain on the C++ template facility (which even in its final ISO form is barely adequate for the task) that it's amazing that they work at all. The book is full of ingenious work-arounds to overcome language limitations.

I just wish that more current compilers would accept the code. Sadly, Visual C++ 6.0 is a long way from this level of standard-conformance. Hopefully VC++ .NET will be better.

Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No

Share your thoughts with other customers: Create your own review
 
 
 
Most Recent Customer Reviews

4.0 out of 5 stars Great book for learning advanced templates
However found that it was difficult for most developer to read and master the concepts, so it was hard to find developers who could maintain the code.
Published 4 days ago by James

5.0 out of 5 stars Very interesting book
This book centers around the author's Loki library. Along the way he develops many and various utility template classes. Read more
Published 5 months ago by Thomas E. Seeley

5.0 out of 5 stars Good explanations, great ideas.
I had heard good things about this book, and now would agree with almost everything I'd heard. The concepts presented are deceptively simple, but add up to a wonderful new way of... Read more
Published 11 months ago by Caleb Huitt

4.0 out of 5 stars Highly technical but serves only a certain niche
I have this book for a couple of years already. I have not simply browsed through the book, but have actually taken the time to utilize the techniques of the typelists in chapter... Read more
Published 17 months ago by Yuanchyuan Sheu

5.0 out of 5 stars Seminal book
I do not know what to call this magnificent work. An work of art or excellence by Mr Alexandrescu. It is great book, only for typelists chapter, it is worthed to buy. Read more
Published on July 6, 2008 by Cumhur Guzel

4.0 out of 5 stars Enter the World of Metaprogramming
Although this book is now six-plus years old, compilers have finally caught up with the implementation allowing the techniques outlined in the book to be used in production code... Read more
Published on October 22, 2007 by Brent Fulgham

5.0 out of 5 stars Great book with an important caveat
That caveat being: the book is not of immediate _practical_ value to most C++ programmers (other than as a brain teaser or inspiration, both of which are of course very... Read more
Published on October 19, 2007 by J. Bielawski

3.0 out of 5 stars Interesting; over-complex
This book is mostly about what you COULD do with templates, but IMO probably wouldn't want to. The Loki library that it describes provides some uber-generic components using a lot... Read more
Published on September 14, 2007 by Alexander Rosen

4.0 out of 5 stars Great techniques, not for the normal programmer
Finally I picked up "modern C++ design". It was on my list for a long time. Last years I've been diving more in Java, Groovy, Ruby and other languages. Read more
Published on May 19, 2007 by Bas Vodde

4.0 out of 5 stars Power of generic programming
This is an excellent book on the power of C++ templates. Even though I have been using templates for several years to create simple reusable code etc, this book has opened my eyes... Read more
Published on May 13, 2007 by R. Bailey

Only search this product's reviews



Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
 


Active discussions in related forums
Search Customer Discussions
Search all Amazon discussions
   





Look for Similar Items by Category


Look for Similar Items by Subject

 

Feedback

If you need help or have a question for Customer Service, contact us.
 Would you like to update product info or give feedback on images?
Is there any other feedback you would like to provide?

Your comments can help make our site better for everyone.


Your Recent History

 (What's this?)

After viewing product detail pages or search results, look here to find an easy way to navigate back to pages you are interested in.