谷歌C++风格指南

Background
背景

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++特性强大 -> C++难读难维护
很多谷歌的开源项目把C++作为编程语言。每个C++程序员都知道C++有很多强大的特性,但是越强大,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++的难度。在保证程序员可以高效使用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++特性的滥用。C++拥有很多高级特性,它是个很大规模的语言。一些情况下,我们限制或者是禁止去使用某种特性。这样做是为了代码能够简单,同时避免各种错误和问题。这篇指导文章列出了这些特性,解释了为什么应该限制使用它们。

Open-source projects developed by Google conform to the requirements in this guide.
谷歌公司的开源项目都符合这篇导文中提出的要求。

Note that this guide is not a C++ tutorial: we assume that the reader is familiar with the language.
注意这篇文章不进行C++教学:我们假设你熟悉这门语言。

原文地址:https://www.cnblogs.com/faeriesoft/p/4417970.html