Product Details
|
Software "style" is about finding the perfect balance between overhead and functionality... elegance and maintainability... flexibility and excess. In Exceptional C++ Style, legendary C++ guru Herb Sutter presents 40 new programming scenarios designed to analyze not only the what but the why and help you find just the right balance in your software.
Organized around practical problems and solutions, this book offers new insight into crucial C++ details and interrelationships, and new strategies for today's key C++ programming techniques--including generic programming, STL, exception safety, and more. You'll find answers to questions like:
Exceptional C++ Style will help you design, architect, and code with style--and achieve greater robustness and performance in all your C++ software.
The scene: Budapest. A hot summer evening. Looking across the Danube, with a view of the eastern bank.
In the cover photo showing this pastel-colored European scene, what’s the first building that jumps out at you? Almost certainly it’s the Parliament building on the left. The massive neo-Gothic building catches the eye with its graceful dome, thrusting spires, dozens of exterior statues and other ornate embellishments—and catches the eye all the more so because it stands in stark contrast to the more utilitarian buildings around it on the Danube waterfront.
Why the difference? For one thing, the Parliament building was completed in 1902; the other stark, utilitarian buildings largely date from Hungary’s stark and utilitarian Communist era, between World War II and 1989.
“Aha,” you might think, “that explains the difference. All very nice, of course, but what on earth does this have to do with Exceptional C++ Style?”
Certainly the expression of style has much to do with the philosophy and mindset that goes into it, and that is true whether we’re talking about building architecture or software architecture. I feel certain that you have seen software designed on the scale and ornateness of the Parliament building; I feel equally sure that you have seen utilitarian blocky (or should that be “bloc-y”?) software buildings. On the extremes, I am just as convinced that you have seen many gilded lilies that err on the side of style, and many ugly ducklings that err on the side of pushing code out the door (and don’t even turn out to be swans).
Style or Substance?Which is better?
Don’t be too sure you know the answer. For one thing, “better” is an unuseful term unless you define specific measures. Better for what? Better in which cases? For another, the answer is almost always a balance of the two and begins with: “It depends...”
This book is about finding that balance in many detailed aspects of software design and implementation in C++, and knowing your tools and materials well to know when they are appropriate.
Quick: Is the Parliament building a better building, crafted with better style, than the comparatively drab ones around it? It’s easy to say yes unthinkingly—until you have to consider building and maintaining it:
Likewise in software, it is important to find the right balance between construction cost and functionality, between elegance and maintainability, between the potential for growth and excessive ornateness.
We deal with these and similar tradeoffs every day as we go about software design and architecture in C++. Among the questions this book tackles are the following: Does making your code exception-safe make it better? If so, for what meanings of “better,” and when might it not be better? That question is addressed specifically in this book. What about encapsulation; does it make your software better? Why? When doesn’t it? If you’re wondering, read on. Is inlining a good optimization, and when is it done? (Be very very careful when you answer this one.) What does C++’s export feature have in common with the Parliament building? What does std::string have in common with the monolithic architecture of the Danube waterfront in our idyllic little scene?
Finally, after considering many C++ techniques and features, at the end of this book we’ll spend our last section looking at real examples of published code and see what the authors did well, what they did poorly, and what alternatives would perhaps have struck a better balance between workmanlike substance and exceptional C++ style.
What do I hope that this and the other Exceptional C++ books will help to do for you? I hope they will add perspective, add knowledge of details and interrelationships, and add understanding of how balances can be struck in your software’s favor.
Please look one more time at the front cover photo, at the top right—that’s it, right there. We should want to be in the balloon flying over the city, enjoying the full perspective of the whole view, seeing how style and substance coexist and interact and interrelate and intermingle, knowing how to make the tradeoffs and strike the right balances, each choice in its place in the integral and thriving whole.
Yes, I think Budapest is a great city—so rich with history, so replete with metaphor.
The Exceptional SocratesThe Greek philosopher Socrates taught by asking his students questionsÑquestions designed to guide them and help them draw conclusions from what they already knew and to show them how the things they were learning related to each other and to their existing knowledge. This method has become so famous that we now call it the Socratic method. From our point of view as students, Socrates’ legendary ap-proach involves us, makes us think, and helps us relate and apply what we already know to new information.
This book takes a page from Socrates, as did its predecessors, Exceptional C++ Sutter00 and More Exceptional C++ Sutter02. It assumes you’re involved in some aspect of writing production C++ software today, and it uses a question-answer format to teach how to make effective use of standard C++ and its standard library, with a particular focus on sound software engineering in modern C++. Many of the prob-lems are drawn directly from experiences I and others have encountered while working with production C++ code. The goal of the questions is to help you draw conclusions from things you already know as well as things you’ve just learned, and to show how they interrelate. The puzzles will show how to reason about C++ design and programming issues—some of them common issues, some not so common; some of them plain issues, some more esoteric; and a couple because, well, just because they’re fun.
This book is about all aspects of C++. I don’t mean to say that it touches on every detail of C++—that would require many more pages—but rather that it draws from the wide palette of the C++ language and library features to show how apparently unrelated items can be used together to synthesize novel solutions to common problems. It also shows how apparently unrelated parts of the palette interrelate on their own, even when you don’t want them to, and what to do about it. You will find material here about templates and namespaces, exceptions and inheritance, solid class design and design patterns, generic programming and macro magic—and not just as randomized tidbits, but as cohesive Items showing the interrelationships among all these parts of modern C++.
Exceptional C++ Style continues where Exceptional C++ and More Exceptional C++ left off. This book follows in the tradition of the first two: It delivers new material, organized in bite-sized Items and grouped into themed sections. Readers of the first book will find some familiar section themes, now including new material, such as exception safety, generic programming, and optimization and memory management techniques. The books overlap in structure and theme but not in content. This book continues the strong emphasis on generic programming and on using the C++ standard library effectively, including coverage of important template and generic programming techniques.
Versions of most Items originally appeared in magazine columns and on the Internet, particularly as print columns and articles I’ve written for C/C++ Users Journal, Dr. Dobb’s Journal, the former C++ Report, and other publications, and also as Guru of the Week GotW issues #63 to #86.
What I Assume You KnowI 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 such as Bjarne Stroustrup’s The C++ Programming Language Stroustrup00 or Stan Lippman and Josée Lajoie’s C++ Primer, Third Edition Lippman98. Next, be sure to pick up a style guide such as Scott Meyers’ classic Effective C++ books Meyers96, Meyers97. I find the browser-based CD version Meyers99 convenient and useful.
How to Read This BookEach Item in this book is presented as a puzzle or problem, with an introductory header that resembles the following:
##. The Topic of This Item Difficulty: # A few words about what this Item will cover.The topic tag and difficulty rating gives you a hint of what you’re in for, and typically there are both introductory/review questions (“JG,” a term for a new junior-grade military officer) leading to the main questions (“Guru”). Note that the difficulty rating is my subjective guess at how difficult I expect most people will find each problem, so you might well find that a “7” problem is easier for you than some “5” problem. Since writing Exceptional C++ Sutter00 and More Exceptional C++ Sutter02, I’ve regularly received e-mail saying that “Item #N is easier (or harder) than that!” It’s common for different people to vote “easier!” and “harder!” for the same Item. Ratings are personal; any Item’s actual difficulty for you depends on your knowledge and experience and could be easier or harder for someone else. In most cases, though, you should find the rating to be a reasonable guide to what to expect.
You might choose to read the whole book front to back; that’s great, but you don’t have to. You might decide to read all the Items in a section together because you’re particularly interested in that section’s topic; that’s cool too. Except where there are what I call a “miniseries” of related problems which you’ll see designated as Part 1, Part 2, and so on, the Items are pretty independent, and you should feel free to jump around, following the many cross-references among the Items in the book, as well as the many references to the first two Exceptional C++ books. The only guidance I’ll offer is that the miniseries are designed to be read consecutively as a group; other than that, the choice is yours.
Unless I call something a complete program, it’s probably not. Remember that the code examples are usually just snippets or partial programs and aren’t expected to compile in isolation. You’ll usually have to provide some obvious scaffolding to make a complete program out of the snippet shown.
Finally, a word about URLs: On the web, stuff moves. In particular, stuff I have no control over moves. That makes it a real pain to publish random web URLs in a print book lest they become out of date before the book makes it to the printer, never mind after it’s been sitting on your desk for five years.Nearly all the other works I reference are listed in the Bibliography, and I’ve provided an online version with active hyperlinks. If you find that a link printed in this book no longer works, send me e-mail and tell me; I’ll update that redirector to point to the new page’s location (if I can find the page again) or to say that the page no longer exists (if I can’t). Either way, this book’s URLs will stay up to date despite the rigors of print media in an Internet world. Whew.
Tag this product(What's this?)Think of a tag as a keyword or label you consider is strongly related to this product.
Tags will help all customers organize and find favorite items. |
|
Share your thoughts with other customers:
|
||||||||||||||||||||||
|
Most helpful customer reviews
4.0 out of 5 stars
Advanced C++ book to test your knowledge,
By Olivier Langlois "www.OlivierLanglois.net" (Montreal, Quebec Canada) - See all my reviews (REAL NAME)
This review is from: Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions (Paperback)
By having read the 3 books in the serie, I must say that this is my favorite because it has really answered a lot of small questions I had for a long time about several aspects of C++. The only thing that I have disliked is that Mr. Sutter has contradicted himself with one of the advice that he was giving in the first book. The advice was to not write an assignement operator in terms of its copy constructor with the in place new operator and the explicit destructor and I did agree with the reasonning. Now in this book, it is written that is ok to use that idiom if and if and if and he goes for about a paragraph to describe the condition where it is ok to use the pattern. I can imagine that the author had to admit that there might be exceptional situation where it is ok to use that technic in a heated debate but my opinion is that out of context, he should not have mention that it might be ok to use that technic without devoting an entire item on that topic. It did just confuse me and I had to reread the item in the first book to convince me that there was effectively a contradiction between the 2 books and that it was not just my memory playing games with me.
Share your thoughts with other customers: Create your own review
Most Helpful Customer Reviews on Amazon.com (beta) Amazon.com:
4.4 out of 5 stars (10 customer reviews) 19 of 19 people found the following review helpful
5.0 out of 5 stars
Excellent for C++ programmers at all levels,
By Michi "Michi" - Published on Amazon.com
This review is from: Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions (Paperback)
This book is not so much about C++ "style" in the usual sense (that is, how to indent or where to put the curly braces) but rather, about sound coding practices that make your code simpler, better, faster, and more maintainable. What you get is a collection of 40 items that each examine a specific topic, outline the potential problems with a particular approach, and then proceed to show you how things can be improved. Most importantly, each item is strong on the rationale: you are not just told how to do it better, but *why* it is is better to do something in a particular way.There is something for everyone in this book, from the obscure and astonishing ("How many consecutive '+' characters can appear in a standards-conforming program?"), to the pragmatic ("When should you use inlining?"), to the advanced ("How generic should you make your templates, and why?"). I've been programming in C++ for 16 years now, and I learned quite a lot from reading this book. Yet, you don't have to be a C++ veteran to appreciate the advice that is provided: novice C++ programmers will find the items just as useful as old hands at C++ programming. The book is well written, in clear and concise style, and never boring. (A number of creative footnotes even produce the occasional laugh.) The material is well organized, presented in groups of topics that relate to each other, and the table of contents and index make it easy to locate a topic for reference. And the bibliography contains things that are actually worth reading, rather than meaningless filler material. I most appreciated Herb's honesty when dealing with various not-so-great aspects of C++. He doesn't shy back from pointing out when things are bad and simply shouldn't be used (such as exception specifications). The items I enjoyed the most are about the design of std::string, which Herb dissects (or should I say "trashes"?) unmercifully. To me, the book is worth buying just for these items alone because they provide splendid insight into what distinguishes good design from bad design, and how methodical and clear thinking is essential to writing good programs. ("Beware the behemoth of the Winnebago class -- it will haunt you onto the fourth generation...") In summary, I think every C++ programmer should read this book. Yes, it's *that* good. 27 of 29 people found the following review helpful
5.0 out of 5 stars
Simply exceptional,
By ART SEDIGHI - Published on Amazon.com
This review is from: Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions (Paperback)
Did you know the "snprinf(...)" that we use in our programs is not part of the C++ standard? Did you know that the "export" keyword has little or no benefit to C++ templates and the source code of the implementation still needs to be shipped? Do you know what primary templates are? Did you know that Accessibility checking is the last things a compiler checks for - after checking for overload resolution? Do you make your virtual functions private? Well, you really should. Do you know what Herb Sutter's favorite Starbucks drink is? Do you know what the "const" keyword really buys you? How about inline-ing?If you answered no to even one of these questions, you should read Herb Sutter's Exceptional C++ Style, 40 New Engineering Puzzles, Programming Problems, and Solutions book. I must say that I am not doing justice in reviewing this book, since each item in this 40 item collection should really reviewed independently as each one is very well written, useful and practical. To start, this book is well organized into sections as one would expect such type of organization with book of such type. One differing aspect is with the Case Studies at the end of the book. Mostly around the string class, but nonetheless, they are very informative. The author has taken already-out-there-being-used code and depicts them for their style. Various "guidelines" given by the author in the Case Studies section makes the developer's life a whole lot simpler. One of my favorite guidelines - throughout the book - is the one the author gives about the decision that each developer goes thru when designing a class and wants to make a decision about what to make friend, a member and a non-member of a class: - Always make it a member if it has to be one. - Prefer to make it a member if it needs access to internals - In all other cases, prefer to make it a non-member friend. Simple? Well, it should be. There are plenty of explanation and example for each of the given guidelines. As one reads and understands the given guidelines, they are very easy memorize-able. Three small phrases which we call have used or even know when we write code, but they are all on paper and are made very simple to be carved in one's memory. The author makes a great deal of effort to follow this routine, an engineering approach to solving problems and designing software, throughout the book. This book is like having an engineering notebook with fun-facts and pointers and hints that you always wanted to know and now you do! I should really have gone thru the book in some sort of a chronological order, but I figured that the Case Studies are rather unique in this book and require special attention. Who would have thought that there is so much to the Standard Template Libraries? Did you know that there are functions/methods in the STL that one can not even use with the STL? (Item 4) "...the bottom line is that you can't reliably form pointers to standard library member functions and still have portable code." I was blown away by this bold statement. What do you mean? You want to tell me that standard doesn't really constitute a standard? Want to tell me that my code that I have been so carefully writing using the STL might not be portable after all? There are rather amazing twists in the C++ language, and the author elegantly describes these abnormalities, and it the process the author manages to blow your mind away. A great amount of attention is given throughout the book to the "boost" libraries. I was not familiar with "boost", and I was interested enough after reading this book that I will make a point to read up on it. The author does make a claim that the boost library might become part of the C++ standard, which would explain why the author has referred to the boost library so much in his text. A good deal of attention was also given to Inheritance and Polymorphism as one would expect. You see this topic all the time in every C++ book, but there are still grounds uncovered and stones unturned. You can't ever have enough of this specific topic. The most intriguing part is Item 16 about a class's Private Parts! If you think that Private members are really hidden, then think again and read Item 16 - you will be amazed at how the C++ compiler treats private members and methods. Virtuality and virtual classes: you know them as the cause of needing to stay at work late to debug your code, and the reason behind male pattern baldness due to the stress that they cause you. If this is the least bit true, then Item 18 is for you. The best quote out of this item is made when the author talks about public virtual functions: "Prefer to make virtual functions private." Why you ask? Read Item 18 and find out. A wealth of information is in this book. Herb Sutter has done it again. This book is a must for every C++ programmer as it further unleashes the great power and flexibility of the C++ programming language. 10 of 10 people found the following review helpful
5.0 out of 5 stars
Yet More Exceptional C++,
By Paul M. Dubuc - Published on Amazon.com
This review is from: Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions (Paperback)
This book is a great addition to Herb Sutter's previous two "Exceptional" C++ books. It follows a very similar question and answer format that helps the reader think about a problem before being given the answer and so is more effective in helping you learn than are some other books. It gives very clear and concise answers to each problem with guidelines drawn from each lesson highlighted throughout the text that help you remember the main points.The only problem now that I have is, with all three of these books on my shelf, it takes longer to figure out where I read something of on a particular topic. The topical sections of each book overlap (E.g., sections covering exception eafety, memory managment and inheritance appear in all three books.) and they are all written at the same level of difficulty overall. The later books do make plenty of references back to the earlier ones as well as some other very good C++ books but this material would be better organized in one volume rather than three. Perhaps they should have been published as three editions of the same book rather than three separate books. That's the only thing I can think of that would have made them more useful. Even so this book, like the other two, is very good exercise for keeping C++ programming skills sharp. Well done! |
|
|