没有合适的资源?快使用搜索试试~ 我知道了~
C++_Coding_Standards_101_Rule
需积分: 10 19 下载量 177 浏览量
2018-08-24
15:54:26
上传
评论
收藏 2.1MB PDF 举报
温馨提示
试读
659页
C++ Coding Standards 101 Rule, Andrei Alexandrescu
资源推荐
资源详情
资源评论
The C++ In-Depth Series
Bjarne Stroustrup, Editor
"I have made this letter longer than usual, because I lack the time to make it
short."
B
LAISE
P
ASCAL
The advent of the ISO/ANSI C++ standard marked the beginning of a new era for C++
programmers. The standard offers many new facilities and opportunities, but how can a
real-world programmer find the time to discover the key nuggets of wisdom within this mass
of information? The C++ In-Depth Series minimizes learning time and confusion by giving
programmers concise, focused guides to specific topics.
Each book in this series presents a single topic, at a technical level appropriate to that topic.
The Series' practical approach is designed to lift professionals to their next level of
programming skills. Written by experts in the field, these short, in-depth monographs can be
read and referenced without the distraction of unrelated material. The books are
cross-referenced within the Series, and also reference The C++ Programming Language by
Bjarne Stroustrup.
As you develop your skills in C++, it becomes increasingly important to separate essential
information from hype and glitz, and to find the in-depth content you need in order to grow.
The C++ In-Depth Series provides the tools, concepts, techniques, and new approaches to
C++ that will give you a critical edge.
Titles in the Series
Accelerated C++: Practical Programming by Example, Andrew Koenig and Barbara E. Moo
Applied C++: Practical Techniques for Building Better Software, Philip Romanik and Amy Muntz
The Boost Graph Library: User Guide and Reference Manual, Jeremy G. Siek, Lie-Quan Lee,
and Andrew Lumsdaine
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices, Herb Sutter and Andrei
Alexandrescu
C++ In-Depth Box Set, Bjarne Stroustrup, Andrei Alexandrescu, Andrew Koenig, Barbara E.
Moo, Stanley B. Lippman, and Herb Sutter
C++ Network Programming, Volume 1: Mastering Complexity with ACE and Patterns, Douglas
C. Schmidt and Stephen D. Huston
C++ Network Programming, Volume 2: Systematic Reuse with ACE and Frameworks, Douglas
C. Schmidt and Stephen D. Huston
C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond,
David Abrahams and Aleksey Gurtovoy
Essential C++, Stanley B. Lippman
Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions, Herb Sutter
Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions,
Herb Sutter
Modern C++ Design: Generic Programming and Design Patterns Applied, Andrei Alexandrescu
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions,
Herb Sutter
For more information, check out the series web site at
www.awprofessional.com/series/indepth/
Preface
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 listnot the size of his vocabulary.
Alan Perlis [emphasis ours]
The best thing aboutstandards 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 pr
actices 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 offyou can use them to bring the team to a common level and
provide a basis for code reviews.
剩余658页未读,继续阅读
资源评论
wuhui_gdnt
- 粉丝: 614
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功