Loading...

Google C++ 编程风格指南(0):背景

Google C++ 编程风格指南(0):背景

C++ is the main development language used by many of Google’s open-source projects. As every C++ programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain.
C++ 是 Google 很多开源项目使用的主要开发语言。如每个 C++ 程序员知道的,这门语言拥有很多强大的特性,但强大也使之复杂,造成的负面影响是代码更易产生 bug、更难读和维护。

The goal of this guide is to manage this complexity by describing in detail the dos and don’ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to use C++ language features productively.
这份指南的目的是通过细致地描述在编写 C++ 代码时的“要”和“不要”来克服它的复杂性。这些规则使得在允许程序员有效使用 C++ 语言特性的情况下,代码仍然易于管理。

Style, also known as readability, is what we call the conventions that govern our C++ code. The term Style is a bit of a misnomer, since these conventions cover far more than just source file formatting.
风格,亦被称为可读性,是我们控制 C++ 代码的规矩或是习惯。“风格”稍微有一点用词不当,因为这些规矩或习惯涵盖的内容远不止编写源代码文件的格式。

One way in which we keep the code base manageable is by enforcing consistency. It is very important that any programmer be able to look at another’s code and quickly understand it. Maintaining a uniform style and following conventions means that we can more easily use “pattern-matching” to infer what various symbols are and what invariants are true about them. Creating common, required idioms and patterns makes code much easier to understand. In some cases there might be good arguments for changing certain style rules, but we nonetheless keep things as they are in order to preserve consistency.
保持代码可管理的一个方式是增加一致性。这对任一个程序员读懂别人的代码并能快速理解非常重要。维持一个统一的风格并遵循这些规矩,意味着我们能够更加轻松地使用“模式匹配”来推断不同的符号分别代表什么。一般来说,遵循规范和模式的代码更具有易读性。虽然在某些情况下改变特定的风格会带来好处,但我们仍应与之保持一致。

Another issue this guide addresses is that of C++ feature bloat. C++ is a huge language with many advanced features. In some cases we constrain, or even ban, use of certain features. We do this to keep code simple and to avoid the various common errors and problems that these features can cause. This guide lists these features and explains why their use is restricted.
这份指南要说明的另一个问题是 C++ 的特性膨胀。C++ 是一门拥有很多高级特性的巨大的语言。在一些情况下,我们尽量避免甚至是禁止使用某些特性。这样做,我们是为了保持代码的简单,避免这些特性带来各式各样的错误和问题。指南有一个列表列出这些特性,并解释为什么它们的使用是受限的。

Open-source projects developed by Google conform to the requirements in this guide.
Google 开发的开源项目遵守了这份指南的要求。

Note that this guide is not a C++ tutorial: we assume that the reader is familiar with the language.
[注意] 这份指南并不是一本 C++ 教程:我们假设读者已经熟悉这门语言。

——————————
声明:转载请以超级链接的形式注明本文地址http://hellobmw.com/archives/google-cpp-style-guide-0-background.html)。
原文地址:Google C++ Style Guide
本文由 北极冰仔 翻译

0Comment(s). Blabla or Trackback

Blabla ↓

Connecting to server...