google的编码规范----背景(一)

 

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.

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.

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.

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.

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.

 

 

背景

Google非常多的开源项目都使用C++语言做为主要的开发语言。每一个C++的程序员都知道,这种语言有着许多非常强大的功能,但是这些功能使得语言变得非常的复杂,以至于存在着很多有错误倾向的代码并且代码很难阅读和维护。

这篇指导的目标是通过描述在写C++代码的时候应该做和不应该做的细节来降低这种复杂性,并使得复杂性得到控制。这些规则的存在可以让编程者使用C++语言更多的功能,并且可以保持语言的可维护性。

代码风格,也被称为代码的可读性,是我们编写代码的规范。用风格这个词来描述不是很准确,因为这些规范覆盖的内容远远超过了源代码的格式。

我们保持代码可维护性的方法之一是保持代码风格的一致性。这一点非常的重要,因为它可以让任何一个程序员很容易的看懂其它程序员的代码并且可以很快的理解代码。保持统一的风格并且遵守这些规范意味着我们可以很容易的使用“统一的规则”去推断变量的含义并且知道哪些值对这个变量而言是正确的。创建共同的,统一的风格和模式可以让代码更容易理解。在某些情况下我们可能会为了改变特定的代码规则而争吵,但是我们为了保持一致性而不得不去遵守这些规则。

代码规范涉及的另一个问题是大量C++特性的使用。C++语言是有着很多高级特性并且功能强大的语言。在某些情况下,我们限制,甚至禁止使用某些功能。我们这样做是为了保持代码简单,避免使用这些功能导致很多很常见的错误和问题。这个规范列举了这些功能并且解释了为什么要严格限制使用它。

Google开发的开源项目都被要求遵守这些规范。

需要注意的是这些规范不是C++的教程:我们认为读者都是非常熟悉这门语言的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值