BN.com Gift Guide

Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions / Edition 1

Paperback (Print)
Buy New
Buy New from BN.com
$40.74
Used and New from Other Sellers
Used and New from Other Sellers
from $14.94
Usually ships in 1-2 business days
(Save 70%)
Other sellers (Paperback)
  • All (17) from $14.94   
  • New (7) from $29.79   
  • Used (10) from $14.94   

Overview

Exceptional C++ shows by example how to go about sound software engineering in standard C++. Do you enjoy solving thorny C++ problems and puzzles? Do you relish writing robust and extensible code? Then take a few minutes and challenge yourself with some tough C++ design and programming problems.

The puzzles and problems in Exceptional C++ not only entertain, they will help you hone your skills to become the sharpest C++ programmer you can be. Many of these problems are culled from the famous Guru of the Week feature of the Internet newsgroup comp.lang.c++.moderated, expanded and updated to conform to the official ISO/ANSI C++ Standard.

Each problem is rated according to difficulty and is designed to illustrate subtle programming mistakes or design considerations. After you've had a chance to attempt a solution yourself, the book then dissects the code, illustrates what went wrong, and shows how the problem can be fixed. Covering a broad range of C++ topics, the problems and solutions address critical issues such as:

  • Generic programming and how to write reusable templates
  • Exception safety issues and techniques
  • Robust class design and inheritance
  • Compiler firewalls and the Pimpl Idiom
  • Name lookup, namespaces, and the Interface Principle
  • Memory management issues and techniques
  • Traps, pitfalls, and anti-idioms
  • Optimization

Try your skills against the C++ masters and come away with the insight and experience to create more efficient, effective, robust, and portable C++ code.

0201615622B04062001

Read More Show Less

Editorial Reviews

Booknews
Designed to help experienced C++ programmers improve their skills, the problems and solutions address generic programming and how to write reusable templates, exception-safety issues and techniques, robust class design and inheritance, compiler firewalls and the Pimpl Idiom, name lookup and the Interface Principle, memory management, and optimization. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780201615623
  • Publisher: Addison-Wesley
  • Publication date: 11/18/1999
  • Series: C++ in Depth Series
  • Edition description: New Edition
  • Edition number: 1
  • Pages: 240
  • Product dimensions: 9.14 (w) x 7.30 (h) x 0.44 (d)

Meet the Author

Herb Sutter is the author of three highly acclaimed books, Exceptional C++ Style, Exceptional C++, and More Exceptional C++ (Addison-Wesley). He chairs the ISO C++ standards committee, and is contributing editor and columnist for C/C++ Users Journal. As a software architect for Microsoft, Sutter leads the design of C++ language extensions for .NET programming.

Read More Show Less

Read an Excerpt

Exceptional C++ shows by example how to go about solid software engineering. Along with a lot of other material, this book includes expanded versions of the first 30 issues of the popular Internet C++ feature Guru of the Week (or, in its short form, GotW), a series of self-contained C++ engineering problems and solutions that illustrate specific design and coding techniques.

This book isn't a random grab-bag of code puzzles; it's primarily a guide to sound real-world enterprise software design in C++. It uses a problem/solution format because that's the most effective way I know to involve you, gentle reader, in the ideas behind the problems and the reasons behind the guidelines. Although the Items cover a variety of topics, you'll notice recurring themes that focus on enterprise development issues, particularly exception safety, sound class and module design, appropriate optimization, and writing portable standards-conforming code.

I hope you find this material useful in your daily work. But I also hope you find at least a few nifty thoughts and elegant techniques, and that from time to time, as you're reading through these pages, you'll suddenly have an "Aha! Gnarly!" moment. After all, who says software engineering has to be dull?

How to Read This Book

I expect that you already know the basics of C++. If you don't, start with a good C++ introduction and overview (good choices are a classic tome like Bjarne Stroustrup's The C++ Programming Language, Third Edition 1 or Stan Lippman and JosEe Lajoie's C++ Primer, Third Edition 2 ), and then be sure to pick up a style guide like Scott Meyers' classic Effective C++ books (I find the browser-based CD version convenient and useful).3

Each item in this book is presented as a puzzle or problem, with an introductory header that looks like this:

ITEM ##: THE TOPIC OF THIS PUZZLE

DIFFICULTY: X

The topic tag and difficulty rating (typically anything from 3 to 9-1/2, based on a scale of 10) gives you a hint of what you're in for. Note that the difficulty rating is my own subjective guess at how difficult I expect most people will find each problem, so you may well find that a given 7 problem is easier for you than another 5 problem. Still, it's better to be prepared for the worst when you see a 9-1/2 monster coming down the pike.

You don't have to read the sections and problems in order, but in several places there are "miniseries" of related problems that you'll see designated as "Part 1," "Part 2," and so onosome all the way up to "Part 10." Those miniseries are best read as a group.

How We Got Here: GotW and PeerDirect

The C++ Guru of the Week series has come a long way. GotW was originally created late in 1996 to provide interesting challenges and ongoing education for our own development team here at PeerDirect. I wrote it to provide an entertaining learning tool, including rants on things like the proper use of inheritance and exception safety. As time went on, I also used it as a means to provide our team with visibility to the changes being made at the C++ standards meetings. Since then, GotW has been made available to the general C++ public as a regular feature of the Internet newsgroup comp.lang.c++.moderated, where you can find each new issue's questions and answers (and a lot of interesting discussion).

Using C++ well is important at PeerDirect for many of the same reasons it's important in your company, if perhaps to achieve different goals. We happen to build systems softwareo for distributed databases and database replicationoin which enterprise issues such as reliability, safety, portability, efficiency, and many others are make-or-break concerns. The software we write needs to be able to be ported across various compilers and operating systems; it needs to be safe and robust in the presence of database transaction deadlocks and communications interruptions and programming exceptions; and it's used by customers to manage tiny databases sitting inside smart cards and pop machines or on PalmOS and WinCE devices, through to departmental Windows NT and Linux and Solaris servers, through to massively parallel Oracle back-ends for Web servers and data warehouseso with the same software, the same reliability, the same code. Now that's a portability and reliability challenge, as we creep up on half a million tight, noncomment lines of code.

To those of you who have been reading Guru of the Week on the Internet for the past few years, I have a couple of things to say:

  • Thank you for your interest, support, e-mails, kudos, corrections, comments, criticisms, questionsoand especially for your requests for the GotW series to be assembled in book form. Here it is; I hope you enjoy it.
  • This book contains a lot more than you ever saw on the Internet.

Exceptional C++ is not just a cut-and-paste of stale GotW issues that are already floating out there somewhere in cyberspace. All the problems and solutions have been considerably revised and reworkedofor example, Items 8 through 17 on exception safety originally appeared as a single GotW puzzle and have now become an in-depth, 10-part miniseries. Each problem and solution has been examined to bring it up to date with the then-changing, and now official, C++ standard.

So, if you've been a regular reader of GotW before, there's a lot that's new here for you. To all faithful readers, thanks again, and I hope this material will help you continue to hone and expand your software engineering and C++ programming skills.

Herb Sutter
June 1999

1. Stroustrup B. The C++ Programming Language, Third Edition (Addison Wesley Longman, 1997).
2. Lippman S. and Lajoie J. C++ Primer, Third Edition (Addison Wesley Longman, 1998).
3. Meyers S. Effective C++ CD: 85 Specific Ways to Improve Your Programs and Designs (Addison Wesley Longman, 1999). An online demo is available at http://www.meyerscd.awl.com.

Read More Show Less

Table of Contents

GENERIC PROGRAMMING AND THE C++ STANDARD LIBRARY.

Item 1: Iterators.

Item 2: Case-Insensitive Strings-Part 1.

Item 3: Case-Insensitive Strings-Part 2.

Item 4: Maximally Reusable Generic Containers-Part 1.

Item 5: Maximally Reusable Generic Containers-Part 2.

Item 6: Temporary Objects.

Item 7: Using the Standard Library (or, Temporaries Revisited).

EXCEPTION-SAFETY ISSUES AND TECHNIQUES.

Item 8: Writing Exception-Safe Code-Part 1.

Item 9: Writing Exception-Safe Code-Part 2.

Item 10: Writing Exception-Safe Code-Part 3.

Item 11: Writing Exception-Safe Code-Part 4.

Item 12: Writing Exception-Safe Code-Part 5.

Item 13: Writing Exception-Safe Code-Part 6.

Item 14: Writing Exception-Safe Code-Part 7.

Item 15: Writing Exception-Safe Code-Part 8.

Item 16: Writing Exception-Safe Code-Part 9.

Item 17: Writing Exception-Safe Code-Part 10.

Item 18: Code Complexity-Part 1.

Item 19: Code Complexity-Part 2.

CLASS DESIGN AND INHERITANCE.

Item 20: Class Mechanics.

Item 21: Overriding Virtual Functions.

Item 22: Class Relationships-Part 1.

Item 23: Class Relationships-Part 2.

Item 24: Uses and Abuses of Inheritance.

Item 25: Object-Oriented Programming.

COMPILER FIREWALLS AND THE PIMPL IDIOM.

Item 26: Minimizing Compile-time Dependencies-Part 1.

Item 27: Minimizing Compile-time Dependencies-Part 2.

Item 28: Minimizing Compile-time Dependencies-Part 3.

Item 29: Compilation Firewalls.

Item 30: The “Fast Pimpl” Idiom.

NAME LOOKUP, NAMESPACES, AND THE INTERFACE PRINCIPLE.

Item 31: Name Lookup and the Interface Principle-Part 1.

Item 32: Name Lookup and the Interface Principle-Part 2.

Item 33: Name Lookup and the Interface Principle-Part 3.

Item 34: Name Lookup and the Interface Principle-Part 4.

MEMORY MANAGEMENT.

Item 35: Memory Management-Part 1.

Item 36: Memory Management-Part 2.

Item 37: auto_ptr.

TRAPS, PITFALLS, AND ANIT-IDIOMS.

Item 38: Object Identity.

Item 39: Automatic Conversions.

Item 40: Object Lifetimes-Part 1.

Item 41: Object Lifetimes-Part 2.

MISCELLANEOUS TOPICS.

Item 42: Variable Initialization—Or Is It?

Item 43: Const-Correctness.

Item 44: Casts.

Item 45: bool.

Item 46: Forwarding Functions.

Item 47: Control Flow.

Afterword.

Bibliography.

Index. 0201615622T04062001

Read More Show Less

Preface

Exceptional C++ shows by example how to go about solid software engineering. Along with a lot of other material, this book includes expanded versions of the first 30 issues of the popular Internet C++ feature Guru of the Week (or, in its short form, GotW), a series of self-contained C++ engineering problems and solutions that illustrate specific design and coding techniques.

This book isn't a random grab-bag of code puzzles; it's primarily a guide to sound real-world enterprise software design in C++. It uses a problem/solution format because that's the most effective way I know to involve you, gentle reader, in the ideas behind the problems and the reasons behind the guidelines. Although the Items cover a variety of topics, you'll notice recurring themes that focus on enterprise development issues, particularly exception safety, sound class and module design, appropriate optimization, and writing portable standards-conforming code.

I hope you find this material useful in your daily work. But I also hope you find at least a few nifty thoughts and elegant techniques, and that from time to time, as you're reading through these pages, you'll suddenly have an "Aha! Gnarly!" moment. After all, who says software engineering has to be dull?

How to Read This Book

I expect that you already know the basics of C++. If you don't, start with a good C++ introduction and overview (good choices are a classic tome like Bjarne Stroustrup's The C++ Programming Language, Third Edition 1 or Stan Lippman and JosEe Lajoie's C++ Primer, Third Edition 2 ), and then be sure to pick up a style guide like Scott Meyers' classic Effective C++ books (I find the browser-based CD version convenient and useful). 3

Each item in this book is presented as a puzzle or problem, with an introductory header that looks like this:

ITEM ##: THE TOPIC OF THIS PUZZLE DIFFICULTY: X

The topic tag and difficulty rating (typically anything from 3 to 9-1/2, based on a scale of 10) gives you a hint of what you're in for. Note that the difficulty rating is my own subjective guess at how difficult I expect most people will find each problem, so you may well find that a given 7 problem is easier for you than another 5 problem. Still, it's better to be prepared for the worst when you see a 9-1/2 monster coming down the pike.

You don't have to read the sections and problems in order, but in several places there are "miniseries" of related problems that you'll see designated as "Part 1," "Part 2," and so onosome all the way up to "Part 10." Those miniseries are best read as a group.

How We Got Here: GotW and PeerDirect

The C++ Guru of the Week series has come a long way. GotW was originally created late in 1996 to provide interesting challenges and ongoing education for our own development team here at PeerDirect. I wrote it to provide an entertaining learning tool, including rants on things like the proper use of inheritance and exception safety. As time went on, I also used it as a means to provide our team with visibility to the changes being made at the C++ standards meetings. Since then, GotW has been made available to the general C++ public as a regular feature of the Internet newsgroup comp.lang.c++.moderated, where you can find each new issue's questions and answers (and a lot of interesting discussion).

Using C++ well is important at PeerDirect for many of the same reasons it's important in your company, if perhaps to achieve different goals. We happen to build systems softwareo for distributed databases and database replicationoin which enterprise issues such as reliability, safety, portability, efficiency, and many others are make-or-break concerns. The software we write needs to be able to be ported across various compilers and operating systems; it needs to be safe and robust in the presence of database transaction deadlocks and communications interruptions and programming exceptions; and it's used by customers to manage tiny databases sitting inside smart cards and pop machines or on PalmOS and WinCE devices, through to departmental Windows NT and Linux and Solaris servers, through to massively parallel Oracle back-ends for Web servers and data warehouseso with the same software, the same reliability, the same code. Now that's a portability and reliability challenge, as we creep up on half a million tight, noncomment lines of code.

To those of you who have been reading Guru of the Week on the Internet for the past few years, I have a couple of things to say:

  • Thank you for your interest, support, e-mails, kudos, corrections, comments, criticisms, questionsoand especially for your requests for the GotW series to be assembled in book form. Here it is; I hope you enjoy it.
  • This book contains a lot more than you ever saw on the Internet.

Exceptional C++ is not just a cut-and-paste of stale GotW issues that are already floating out there somewhere in cyberspace. All the problems and solutions have been considerably revised and reworkedofor example, Items 8 through 17 on exception safety originally appeared as a single GotW puzzle and have now become an in-depth, 10-part miniseries. Each problem and solution has been examined to bring it up to date with the then-changing, and now official, C++ standard.

So, if you've been a regular reader of GotW before, there's a lot that's new here for you. To all faithful readers, thanks again, and I hope this material will help you continue to hone and expand your software engineering and C++ programming skills.

Herb Sutter
June 1999

1. Stroustrup B. The C++ Programming Language, Third Edition (Addison Wesley Longman, 1997).
2. Lippman S. and Lajoie J. C++ Primer, Third Edition (Addison Wesley Longman, 1998).
3. Meyers S. Effective C++ CD: 85 Specific Ways to Improve Your Programs and Designs (Addison Wesley Longman, 1999). An online demo is available at http://www.meyerscd.awl.com.

0201615622P04062001

Read More Show Less

Foreword

This is a remarkable book, but it wasn't until I had nearly finished reading it that I realized just how remarkable it is. This could well be the first book ever written for people who are already familiar with C++—all of C++. From language features to components of the standard library to programming techniques, this book skips from topic to topic, always keeping you slightly off balance, always making sure you're paying attention. Just like real C++ programs. Class design bumps into the behavior of virtual functions, iterator conventions run up against name lookup rules, assignment operators sideswipe exception safety, compilation dependencies cross paths with exported templates. Just like they do in real programs. The result is a dizzying maelstrom of language features, library components, and programming techniques at once both chaotic and magnificent. Just like real programs.

I pronounce GotW such that it rhymes with "Gotcha," and perhaps that's fitting. As I compared my solutions to the book's quizzes against Sutter's answers, I fell into the traps he (and C++) laid before me more often than I'd like to admit. I could almost see Herb smiling and softly saying "Gotcha!" for each error I made. Some may argue that this proves I don't know much about C++. Others may claim it demonstrates that C++ is too complex for anyone to master. I believe it shows that when you're working in C++, you have to think carefully about what you're doing. C++ is a powerful language designed to help solve demanding problems, and it's important that you hone your knowledge of the language, its library, and its programming idioms as finely as you can. The breadthof topics in this book will help you do that. So will its unique quiz-based format. Veteran readers of the C++ newsgroups know how difficult it is to be proclaimed a Guru of the Week. Veteran participants know it even better. On the Internet, of course, there can be only one guru each week, but, backed by the information in this book, you can reasonably hope to produce guru-quality code every time you program.

Scott Meyers
June 1999
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)