Modern C++ Design and over one million other books are available for Amazon Kindle. Learn more



or
Sign in to turn on 1-Click ordering
Sell Us Your Item
For a $15.76 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Start reading Modern C++ Design on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.
Sorry, this item is not available in
Image not available for
Color:
Image not available

To view this video download Flash Player

 

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

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

Buy New
$41.27 & FREE Shipping. Details
Rent
$34.58 & this item ships for FREE with Super Saver Shipping. Details
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.
In Stock.
Rented by RentU and Fulfilled by Amazon.
Want it tomorrow, May 22? Choose One-Day Shipping at checkout. Details
Free Two-Day Shipping for College Students with Amazon Student

Formats

Amazon Price New from Used from
Kindle Edition $27.35  
Paperback $41.27  
Sell Back Your Copy for $15.76
No matter where you bought them, get up to 70% back when you sell your books at Amazon.com.
Used Price$29.89
Trade-in Price$15.76
Price after
Trade-in
$14.13

Book Description

February 23, 2001 0201704315 978-0201704310 1
In Modern C++ Design, Andrei Alexandrescu opens new vistas for C++ programmers. Displaying extraordinary creativity and virtuosity, Alexandrescu offers a cutting-edge approach to software design that unites design patterns, generic programming, and C++, enabling programmers to achieve expressive, flexible, and highly reusable code. The book introduces the concept of generic components, reusable design templates that enable an easier and more seamless transition from design to application code, generate code that better expresses the original design intention, and support the reuse of design structures with minimal recoding. The author then shows how to apply this approach to recurring, real-world issues that C++ programmers face in their day-to-day activity. All code is available on the Web, along with Alexandrescu's downloadable Loki C++ library, which provides powerful out-of-the-box functionality for virtually any C++ project. For experienced C++ programmers who have at least some familiarity with the Standard Template Library (STL).

Frequently Bought Together

Modern C++ Design: Generic Programming and Design Patterns Applied + Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition) + Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
Price for all three: $112.44

Buy the selected items together


Editorial Reviews

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.

From the Back Cover

Modern C++ Design is an important book. Fundamentally, it demonstrates ‘generic patterns’ or ‘pattern templates’ as a powerful new way of creating extensible designs in C++–a new way to combine templates and patterns that you may never have dreamt was possible, but is. If your work involves C++ design and coding, you should read this book. Highly recommended.
–Herb Sutter

What’s left to say about C++ that hasn’t already been said? Plenty, it turns out.
–From the Foreword by John Vlissides

In Modern C++ Design, Andrei Alexandrescu opens new vistas for C++ programmers. Displaying extraordinary creativity and programming virtuosity, Alexandrescu offers a cutting-edge approach to design that unites design patterns, generic programming, and C++, enabling programmers to achieve expressive, flexible, and highly reusable code.

This book introduces the concept of generic components–reusable design templates that produce boilerplate code for compiler consumption–all within C++. Generic components enable an easier and more seamless transition from design to application code, generate code that better expresses the original design intention, and support the reuse of design structures with minimal recoding.

The author describes the specific C++ techniques and features that are used in building generic components and goes on to implement industrial strength generic components for real-world applications. Recurring issues that C++ developers face in their day-to-day activity are discussed in depth and implemented in a generic way. These include:

  • Policy-based design for flexibility
  • Partial template specialization
  • Typelists–powerful type manipulation structures
  • Patterns such as Visitor, Singleton, Command, and Factories
  • Multi-method engines

For each generic component, the book presents the fundamental problems and design options, and finally implements a generic solution.

In addition, an accompanying Web site, http://www.awl.com/cseng/titles/0-201-70431-5, makes the code implementations available for the generic components in the book and provides a free, downloadable C++ library, called Loki, created by the author. Loki provides out-of-the-box functionality for virtually any C++ project.

Get a value-added service! Try out all the examples from this book at www.codesaw.com. CodeSaw is a free online learning tool that allows you to experiment with live code from your book right in your browser.



0201704315B11102003

Product Details

  • Paperback: 352 pages
  • Publisher: Addison-Wesley Professional; 1 edition (February 23, 2001)
  • Language: English
  • ISBN-10: 0201704315
  • ISBN-13: 978-0201704310
  • Product Dimensions: 7.4 x 0.7 x 9.2 inches
  • Shipping Weight: 1.4 pounds (View shipping rates and policies)
  • Average Customer Review: 4.4 out of 5 stars  See all reviews (75 customer reviews)
  • Amazon Best Sellers Rank: #48,281 in Books (See Top 100 in Books)

More About the Author

Andrei Alexandrescu coined the colloquial term "modern C++", used today to describe a collection of important C++ styles and idioms. His eponymous book on the topic, Modern C++ Design: Generic Programming and Design Patterns Applied (Addison-Wesley, 2001), revolutionized C++ programming and produced a lasting influence not only on subsequent work on C++, but also on other languages and systems. With Herb Sutter, Andrei is also the coauthor of C++ Coding Standards: 101 Rules, Guidelines, and Best Practices (Addison-Wesley, 2004). Through Andrei's varied work on libraries and applications, as well as his research in machine learning and natural language processing, he has garnered a solid reputation in both industrial and academic circles. Since 2006, he has been second-in-command to Walter Bright, the D programming language inventor and initial implementer. Andrei has been the key designer of many important features of D and has authored a large part of D's standard library, positioning him to write an authoritative book on the new language, appropriately entitled, The D Programming Language. Andrei holds a PhD in Computer Science from the University of Washington and a BS in Electrical Engineering from University "Politehnica" Bucharest. He works as a Research Scientist for Facebook.

Customer Reviews

What to know more, get a copy of the book! "g_m_c"  |  10 reviewers made a similar statement
Each topic is covered thoroughly and is easy to read and understand. Jeff Challender  |  11 reviewers made a similar statement
Most Helpful Customer Reviews
107 of 114 people found the following review helpful
4.0 out of 5 stars template pathology April 7, 2004
By A Customer
Format: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

Comment | 
Was this review helpful to you?
125 of 141 people found the following review helpful
3.0 out of 5 stars Template Showboating July 14, 2001
Format: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.

Comment | 
Was this review helpful to you?
45 of 48 people found the following review helpful
5.0 out of 5 stars After two disappointments... May 24, 2001
Format:Paperback
I was longing for a good book on advanced C++. First, I bought "Multi-Paradigm C++". It does have some insights but author's style is baroque to the extreme. A good cure for insomnia. Then I bought "Generative Programming". I found it too much of a PhD thesis garnished with too much fluff for my taste.

Not wanting to risk anymore, I borrowed this book from a friend... to lose sleep for two nights reading it! It is the book I was looking for: no-nonsense, eye-opening, inspirational. The author's mastery of C++ and the creativity with which he solves real-world problems are phenomenal.

Alexandrescu discusses and implements the following design patterns: Command, Singleton, Proxy (in the form of smart pointers), Factory Method, Abstract Factory, and Visitor. In doing so, he creates highly configurable components that support most variations that accompany the patterns, and allow the component users to add their own variations. This is done through template parameters. The technique is not new but the author documents it thoroughly (coining the Policy-based design term) and uses it very creatively to achieve elegant designs.

The book also has foundation chapters: Techniques, Typelists, and a small object allocator. The latter is not really in sync with the rest of the book, being a low-level component written in straight C++, but in compensation, the chapter on typelists is as meta as you can imagine, and more :-).

In short: a great book if you use C++, especially so if you need to participate in the architectural stage of projects. But the best thing the book has done for me is, it made me extremely excited about programming - a feeling forgotten since my college days. Five stars plus.

Was this review helpful to you?
Most Recent Customer Reviews
2.0 out of 5 stars A bit dated
As a modern day C++ programmer I was hoping to expand my knowledge base and learn about design patterns but I was disappointed. Read more
Published 17 days ago by Eduardo Polanco
5.0 out of 5 stars Brillant but outdate (since C++11)
First of all, I would like to state that this book is amazing. It will teach you general strategies that are very useful and powerful for C++ developers. Read more
Published 27 days ago by Vinicius M. Braganca
5.0 out of 5 stars Not a beginner's book
I do not recommend buying this book unless you have many years hands on experience writing C++ programs - including a reasonable understanding of templates. Read more
Published 2 months ago by Nicolas Olivier
5.0 out of 5 stars The best c++ design book out there
Never has a professional/technical book made such an impact on me.
I've had this book for many years,but decided to write this review only now because after so many years the... Read more
Published 3 months ago by modern c++'ser
5.0 out of 5 stars Brilliant!!
Having a background in Symbian, I am familiar with object factories, singleton, sp etc, what makes this book different is that it enables me grasping the essence immediately.
Published 20 months ago by Yong Zhi
5.0 out of 5 stars Exceptional material
The material presented in this book is mainly for library writers and senior developers who are in charge of software design. Read more
Published on November 25, 2010 by Ankur
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 on July 27, 2010 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 on February 14, 2010 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 on August 14, 2009 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 3... Read more
Published on February 21, 2009 by Yuanchyuan Sheu
Search Customer Reviews
Only search this product's reviews

What Other Items Do Customers Buy After Viewing This Item?


Forums

There are no discussions about this product yet.
Be the first to discuss this product with the community.
Start a new discussion
Topic:
First post:
Prompts for sign-in
 





Look for Similar Items by Category