Code Specification for Google Inc.

Source: Internet
Author: User

Title: C + +, objective-c, Java, Python, R, Shell, Html/css, JavaScript, AngularJS, Common Lisp, Vimscript language, Google's internal generation Code specification documents can now be viewed on GitHub.

The following is a partial C + + code specification, English good can see. : Http://files.cnblogs.com/files/hutiann/cppguide.rar

Google C + + Style Guide Background

C + + is one of the main development languages used by many of Google ' s open-source projects. As every C + + programmer knows, the language have 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 are 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 and still allowing coders to use C + + language features productively.

Style, also known as readability, is the "we call" the conventions that govern our C + + code. The term Style was a bit of a misnomer, since these conventions cover far more than just source file formatting.

Most Open-source projects developed is Google conform to the requirements in this guide.

Note that this guide is a C + + Tutorial:we Assume that the reader was familiar with the language.

Goals of the Style guide

Why does we have this document?

There is a few core goals that we believe this guide should serve. These is the fundamental why s, underlie all of the individual rules. By bringing these ideas to the fore, we hope to ground discussions and make it clearer to our broader community why the RU Les is in place and why particular decisions has been made. If you understand any goals each rule is serving, it should being clearer to everyone when a rule could be waived (some can ), and what sort of argument or alternative would is necessary to change a rule in the guide.

The goals of the style guide as we currently see them is as follows:

Style rules should pull their weight
The
benefit of a style rule must is large enough to justify asking all of our engineers to remember it. The benefit is measured relative to the codebase we would get without the rule, so a rule against a very harmful practice May still has a small benefit if people is unlikely to do it anyway. This principle mostly explains the rules we don't have, rather than the rules we do:for example, goto contravenes many Of the following principles, but are already vanishingly rare, so the Style guide doesn ' t discuss it.
Optimize for the reader, not the writer
Our
codebase (and more individual components submitted to it) are expected to continue for quite some time. As a result, more time would be spent reading the most of our code than writing it. We explicitly choose to optimize for the experience of our average software engineer reading, maintaining, and debugging C Ode in We codebase rather than ease when writing said code. "Leave A Trace for the reader" was a particularly common sub-point of this principle:when something surprising or unusual is happening in a snippet of code (for example, transfer of pointer ownership), leaving textual hints for the reader at th E Point of Use are valuable ( std::unique_ptr demonstrates the ownership transfer unambiguously at the call site).
Be consistent with existing code
Using One style consistently through our codebase lets us focus on other (more important) issues. Consistency also allows for automation:tools this format your code or adjust your #include s only work properly when your C Ode is consistent with the expectations of the tooling. In many cases, rules that is attributed to ' be consistent ' boil down to ' Just pick one and stop worrying about it '; The potential value of allowing flexibility on these points are outweighed by the cost of being people argue over them.
Be consistent with the broader C + + community when appropriate
Consistency with the same-
organizations use C + + have value for the same reasons as consistency within our code B Ase. If a feature in the C + + standard solves a problem, or if some idiom are widely known and accepted, that's an argument for u Sing it. However, sometimes standard features and idioms is flawed, or were just designed without our codebase's needs in mind. In those cases (as described below) it's appropriate to constrain or ban standard features. In some cases we prefer a homegrown or third-party library over a library defined in the C + + standard, either out of Perce Ived superiority or insufficient value to transition the codebase of the standard interface.
Avoid surprising or dangerous constructs
C + + has features that is more surprising or dangerous than one might think at a glance. Some Style Guide Restrictions is in place to prevent falling into these pitfalls. There is a high bar for style guide waivers on such restrictions, because waiving such rules often directly risks Compromi Sing program correctness.
Avoid constructs that our average C + + programmer would find tricky or hard to maintain
C + + has features, May is generally appropriate because of the complexity they introduce to the code. In widely used code, it could be more acceptable to use trickier language constructs, because any benefits of more complex I Mplementation is multiplied widely by usage, and the cost of understanding the complexity does not need to be paid again When working with new portions of the codebase. When in doubt, waivers to the rules of this type can is sought by asking your project leads. This is specifically important-codebase because code ownership and team membership changes over Time:even if ever Yone that works with some piece of code currently understands it, such understanding are not guaranteed to hold a few years From now.
Is mindful of our scale
with a codebase of 100+ million lines and thousands of engineers, some mistakes and simplifications for one engineer Can become costly for many. For instance it's particularly important to avoid polluting the global namespace:name collisions across a codebase of Hun Dreds of millions of lines is difficult to work with and hard to avoid if everyone puts things into the global namespace.
Concede to optimization when necessary
performance optimizations can sometimes is necessary and appropriate, even when they conflict with the other Princip Les of this document.

The intent of this document are to provide maximal guidance with reasonable restriction. As always, the common sense and good taste should prevail. By this we specifically refer to the established conventions of the entire Google C + + community, not just your personal PR Eferences or those of your team. Be skeptical about and reluctant to use clever or unusual constructs:the absence of a prohibition are not the same as a Li Cense to proceed. Use your judgment, and if is unsure, please don ' t hesitate to ask your project leads to get additional input.

Code Specification for Google Inc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.