Programming Books C Java PHP Python Learn more Browse Programming Books
C++ Coding Standards: 101 Rules, Guidelines, and Best Pra... and over one million other books are available for Amazon Kindle. Learn more
Buy New
$38.26
Qty:1
  • List Price: $54.99
  • Save: $16.73 (30%)
Only 3 left in stock (more on the way).
Ships from and sold by Amazon.com.
Gift-wrap available.
Add to Cart
Trade in your item
Get a $10.71
Gift Card.
Have one to sell? Sell on Amazon
Flip to back Flip to front
Listen Playing... Paused   You're listening to a sample of the Audible audio edition.
Learn more
See all 2 images

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices Paperback – November 4, 2004

ISBN-13: 007-6092018117 ISBN-10: 0321113586 Edition: 1st

Buy New
Price: $38.26
31 New from $34.26 25 Used from $25.95
Amazon Price New from Used from
eTextbook
"Please retry"
Paperback
"Please retry"
$38.26
$34.26 $25.95

Free%20Two-Day%20Shipping%20for%20College%20Students%20with%20Amazon%20Student



Frequently Bought Together

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices + 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: $115.63

Buy the selected items together

NO_CONTENT_IN_FEATURE

Shop the new tech.book(store)
New! Introducing the tech.book(store), a hub for Software Developers and Architects, Networking Administrators, TPMs, and other technology professionals to find highly-rated and highly-relevant career resources. Shop books on programming and big data, or read this week's blog posts by authors and thought-leaders in the tech industry. > Shop now

Product Details

  • Paperback: 240 pages
  • Publisher: Addison-Wesley Professional; 1 edition (November 4, 2004)
  • Language: English
  • ISBN-10: 0321113586
  • ISBN-13: 978-0321113580
  • Product Dimensions: 9.4 x 7.5 x 0.4 inches
  • Shipping Weight: 1.1 pounds (View shipping rates and policies)
  • Average Customer Review: 4.4 out of 5 stars  See all reviews (35 customer reviews)
  • Amazon Best Sellers Rank: #116,922 in Books (See Top 100 in Books)

Editorial Reviews

About 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.

Andrei Alexandrescu is the author of the award-winning book Modern C++ Design (Addison-Wesley, 2001) and is a columnist for C/C++ Users Journal.



Excerpt. © Reprinted by permission. All rights reserved.

Get into a rut early: Do the same process the same way. Accumulate idioms. Standardize. The only difference(!) between Shakespeare and you was the size of his idiom list-not the size of his vocabulary.

--Alan Perlis emphasis ours

The best thing about standards is that there are so many to choose from.

--Variously attributed

We want to provide this book as a basis for your team's coding standards for two principal reasons:

A coding standard should reflect the community's best tried-and-true experience: It should contain proven idioms based on experience and solid understanding of the language. In particular, a coding standard should be based firmly on the extensive and rich software development literature, bringing together rules, guidelines, and best practices that would otherwise be left scattered throughout many sources.

Nature abhors a vacuum: If you don't consciously set out reasonable rules, usually someone else will try to push their own set of pet rules instead. A coding standard made that way usually has all of the least desirable properties of a coding standard; for example, many such standards try to enforce a minimalistic C style use of C++.

Many bad coding standards have been set by people who don't understand the language well, don't understand software development well, or try to legislate too much. A bad coding standard quickly loses credibility and at best even its valid guidelines are liable to be ignored by disenchanted programmers who dislike or disagree with its poorer guidelines. That's "at best"--at worst, a bad standard might actually be enforced.

How to Use This Book

Think. Do follow good guidelines conscientiously; but don't follow them blindly. In this book's Items, note the Exceptions clarifying the less common situations where the guidance may not apply. No set of guidelines, however good (and we think these ones are), should try to be a substitute for thinking.

Each development team is responsible for setting its own standards, and for setting them responsibly. That includes your team. If you are a team lead, involve your team members in setting the team's standards; people are more likely to follow standards they view as their own than they are to follow a bunch of rules they feel are being thrust upon them.

This book is designed to be used as a basis for, and to be included by reference in, your team's coding standards. It is not intended to be the Last Word in coding standards, because your team will have additional guidelines appropriate to your particular group or task, and you should feel free to add those to these Items. But we hope that this book will save you some of the work of (re)developing your own, by documenting and referencing widely-accepted and authoritative practices that apply nearly universally (with Exceptions as noted), and so help increase the quality and consistency of the coding standards you use.

Have your team read these guidelines with their rationales (i.e., the whole book, and selected Items' References to other books and papers as needed), and decide if there are any that your team simply can't live with (e.g., because of some situation unique to your project). Then commit to the rest. Once adopted, the team's coding standards should not be violated except after consulting with the whole team.

Finally, periodically review your guidelines as a team to include practical experience and feedback from real use.

Coding Standards and You

Good coding standards can offer many interrelated advantages:

  • Improved code quality: Encouraging developers to do the right things in a consistent way directly works to improve software quality and maintainability.
  • Improved development speed: Developers don't need to always make decisions starting from first principles.
  • Better teamwork: They help reduce needless debates on inconsequential issues and make it easier for teammates to read and maintain each other's code.
  • Uniformity in the right dimension: This frees developers to be creative in directions that matter.

Under stress and time pressure, people do what they've been trained to do. They fall back on habit. That's why ER units in hospitals employ experienced, trained personnel; even knowledgeable beginners would panic.

As software developers, we routinely face enormous pressure to deliver tomorrow's software yesterday. Under schedule pressure, we do what we are trained to do and are used to doing. Sloppy programmers who in normal times don't know good practices of software engineering (or aren't used to applying them) will write even sloppier and buggier code when pressure is on. Conversely, programmers who form good habits and practice them regularly will keep themselves organized and deliver quality code, fast.

The coding standards introduced by this book are a collection of guidelines for writing high-quality C++ code. They are the distilled conclusions of a rich collective experience of the C++ community. Much of this body of knowledge has only been available in bits and pieces spread throughout books, or as word-of-mouth wisdom. This book's intent is to collect that knowledge into a collection of rules that is terse, justified, and easy to understand and follow.

Of course, one can write bad code even with the best coding standards. The same is true of any language, process, or methodology. A good set of coding standards fosters good habits and discipline that transcend mere rules. That foundation, once acquired, opens the door to higher levels. There's no shortcut; you have to develop vocabulary and grammar before writing poetry. We just hope to make that easier.

We address this book to C++ programmers of all levels:

If you are an apprentice programmer, we hope you will find the rules and their rationale helpful in understanding what styles and idioms C++ supports most naturally. We provide a concise rationale and discussion for each rule and guideline to encourage you to rely on understanding, not just rote memorization.

For the intermediate or advanced programmer, we have worked hard to provide a detailed list of precise references for each rule. This way, you can do further research into the rule's roots in C++'s type system, grammar, and object model. At any rate, it is very likely that you work in a team on a complex project. Here is where coding standards really pay off-you can use them to bring the team to a common level and provide a basis for code reviews.

About This Book

We have set out the following design goals for this book:

Short is better than long: Huge coding standards tend to be ignored; short ones get read and used. Long Items tend to be skimmed; short ones get read and used.

Each Item must be noncontroversial: This book exists to document widely agreed upon standards, not to invent them. If a guideline is not appropriate in all cases, it will be presented that way (e.g., "Consider X..." instead of "Do X...") and we will note commonly accepted exceptions.

Each Item must be authoritative: The guidelines in this book are backed up by references to existing published works. This book is intended to also provide an index into the C++ literature.

Each Item must need saying: We chose not to define new guidelines for things that you'll do anyway, that are already enforced or detected by the compiler, or that are already covered under other Items.

Example: "Don't return a pointer/reference to an automatic variable" is a good guideline, but we chose not to include it in this book because all of the compilers we tried already emit a warning for this, and so the issue is already covered under the broader Item 1, "Compile cleanly at high warning levels."

Example: "Use an editor (or compiler, or debugger)" is a good guideline, but of course you'll use those tools anyway without being told; instead, we spend two of our first four Items on "Use an automated build system" and "Use a version control system."

Example: "Don't abuse goto" is a great Item, but in our experience programmers universally know this, and it doesn't need saying any more.

Each Item is laid out as follows:

  • Item title: The simplest meaningful sound bite we could come up with as a mnemonic for the rule.
  • Summary: The most essential points, briefly stated.
  • Discussion: An extended explanation of the guideline. This often includes brief rationale, but remember that the bulk of the rationale is intentionally left in the References.
  • Examples (if applicable): Examples that demonstrate a rule or make it memorable.
  • Exceptions (if applicable): Any (and usually rare) cases when a rule doesn't apply. But beware the trap of being too quick to think: "Oh, I'm special; this doesn't apply in my situation"-that rationalization is common, and commonly wrong.
  • References: See these parts of the C++ literature for the full details and analysis.

In each section, we chose to nominate a "most valuable Item." Often, it's the first Item in a section, because we tried to put important Items up front in each part; but other times an important Item couldn't be put up front, for flow or readability reasons, and we felt the need to call it out for special attention in this way.


More About the Authors

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

Customer Reviews

4.4 out of 5 stars
5 star
21
4 star
8
3 star
5
2 star
1
1 star
0
See all 35 customer reviews
Very easy to read.
David C Utley
You can't live without the practical advice of Effective C++ or the architectural material in C++ Coding Standards.
Jack D. Herrington
I encourage every C++ programmer to buy and read this book cover-to-cover.
Rob Wehrli

Most Helpful Customer Reviews

38 of 38 people found the following review helpful By Amazon Customer on November 22, 2004
Format: Paperback
For many programmers, the term "coding standard" generates a gut-level response. We all know that someone is going to be pushing the "one, true brace style" or the "proper" way to indent code. This subject is probably the best way to generate instantaneous rebellion among a group of programmers.

The first "standard" in "C++ Coding Standards" wipes all of that away with their first rule:

0. Don't sweat the small stuff. (Or: know what not to standardize.)

In one quick entry, Sutter and Alexandrescu sweep all of the indent-level, brace-placement, CamelCase/underscores holy wars into a single category and give a useful bit of advice: <em>Be consistent.</em> The authors point out that any professional programmer should be able to read and write in any of these styles. The differences are basically a matter of personal preference.

From this point on, we get to see a coding standard that is focused on "best practices" and proven techniques for improving code.

This is the only coding standard I've ever seen that would really help a group of programmers improve their work.
1 Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
48 of 52 people found the following review helpful By Jack D. Herrington on November 19, 2004
Format: Paperback
I love both this book and Effective C++ for different reasons. The Effective C++ series is mainly very low level hints that help you avoid the pitfalls that C++ has in store for you. This book, while showing a lot of code, gives a higher level perspective of the areas it covers (e.g. templates, STL, class design, namespaces, etc.). That perspective grounds you in an understanding of the topic, then binds that to some real world code examples. Both approaches are very valuable. I would recommend getting both books. You can't live without the practical advice of Effective C++ or the architectural material in C++ Coding Standards.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
58 of 64 people found the following review helpful By Karl Rosaen on May 1, 2005
Format: Paperback
Sutter and Alexandrescu are certified C++ gurus, and have each written classic works on C++ (Exceptional C++ series, and Modern C++ Design, respectively). So why does this book fall short? Because it doesn't go into the level of detail necessary to make every recommendation meaningful, and instead relies on citations of previous works. And those citations very often fall into a handful of books that every serious C++ programmer should own and understand anyway: Effective C++ series by Scott Meyers, The C++ Programming Language by Bjarne Strousup, and Exceptional C++ by Sutter.

One might argue that 5 books or more is too many, and that this book adds value by providing a one stop ultimate resource for best practices. The problem is that if proper justification isn't provided for each best practice, it's difficult for readers to internalize them. Even if these guys are experts, and a, "trust me" will suffice to believe what they say, it doesn't mean that everyone will understand what they say without diving into the other books that they so often reference. And that brings us back to my main point: you may as well just buy and read the original books in the first place.

Many of the items are complete repeats of items from Scott Meyers books with much less explanation. For example, number 81 of best practices, 'Prefer range operations to single-element operations', is the same as item 5 in 'Effective STL'. However, in Coding Standards, a page is devoted to the explanation; not sufficient if you don't already fully understand why this is a good practice. Meyers, on the other hand, spends 8 pages fully convincing you it is a good idea with several examples. After reading Meyers, I'm going to understand and remember the practice of preferring range member functions.
Read more ›
1 Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
89 of 109 people found the following review helpful By Brent A. Thale on November 16, 2004
Format: Paperback Verified Purchase
I have great respect for both authors from reading their other books/articles, and there are many good ideas in this book, but I was expecting to agree with the authors here much more than I do.

Item 0: Don't sweat the small stuff. The authors say not to overlegislate naming and bracing standards, but they also say "do be consistent" and don't mix styles. From personal experience, I can say the only way to get a group of programmers to be consistent is by "sweating the small stuff" and having well-defined policies that are strictly enforced.

Item 1: Zero tolerance of warnings. Eliminating Level 4 warnings (in Visual C++) from a complex application (as opposed to a library intended for third-party use) is more trouble than it's worth. The authors' suggestion to decrease code readability (Examples 2 and 3) to get around these warnings is quite a bad idea, in my opinion.

Item 59: I wish somehow there could be a better answer to the C++ namespace issue. Giving many symbols (but not all, like preprocessor macros, classes not in a namespace, etc.) two names (the qualified and the unqualified) based on where that symbol appears seems so wrong and at the very least makes searching and cut-and-pasting more difficult.

The authors clearly prefer use of stl over custom containers (although they have not always followed their own advice), but they don't address many issues related to this, like are teams using stl supposed to use the peculiar stl naming practices across the board in all code, so stl dictates naming and all projects would use naming like some_stl_vector.push_back()? Or would code like m_object.DoSomething() be mixed together with the above statement so there really is no standard?
Read more ›
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again

Customer Images

Most Recent Customer Reviews

Search