
When in doubt, waivers to rules of this type The complexity does not need to be paid again when working with new Implementation are multiplied widely by usage, and the cost in understanding Trickier language constructs, because any benefits of more complex The complexity they introduce to the code. Or hard to maintain C++ has features that may not be generally appropriate because of Guide waivers on such restrictions, because waiving such rules oftenĭirectly risks compromising program correctness.Īvoid constructs that our average C++ programmer would find tricky Some style guide restrictions are in place to Avoid surprising or dangerous constructs C++ has features that are more surprising or dangerous than one Value to transition the codebase to the standard interface. The C++ Standard, either out of perceived superiority or insufficient Prefer a homegrown or third-party library over a library defined in In those cases (as described below) it'sĪppropriate to constrain or ban standard features.

Standard features and idioms are flawed, or were just designed without The C++ standard solves a problem, or if some idiom is widely knownĪnd accepted, that's an argument for using it.
Google suggest code#
The same reasons as consistency within our code base. Be consistent with the broader C++ community when appropriate Consistency with the way other organizations use C++ has value for Justification to do things in an old style without considering theīenefits of the new style, or the tendency of the codebase to converge Consistency should not generally be used as a More heavily locally (per file, or for a tightly-related set of Is no clear technical argument, nor a long-term direction. There are limits to consistency it is a good tie breaker when there Outweighed by the cost of having people argue over them. The potential value of allowing flexibility on these points is In many cases, rules that are attributed to "BeĬonsistent" boil down to "Just pick one and stop worrying about it" Work properly when your code is consistent with the expectations of Tools that format your code or adjust your #includes only Be consistent with existing code Using one style consistently through our codebase lets us focus on Transfer of pointer ownership), leaving textual hints for the readerĪt the point of use is valuable ( std::unique_ptrĭemonstrates the ownership transfer unambiguously at the call Surprising or unusual is happening in a snippet of code (for example, Particularly common sub-point of this principle: When something Reading, maintaining, and debugging code in our codebase rather thanĮase when writing said code.
Google suggest software#
We explicitlyĬhoose to optimize for the experience of our average software engineer As a result, more time willīe spent reading most of our code than writing it. Optimize for the reader, not the writer Our codebase (and most individual components submitted to it) isĮxpected to continue for quite some time. Of the following principles, but is already vanishingly rare, so the Style Than the rules we do: for example, goto contravenes many This principle mostly explains the rules we don’t have, rather Still have a small benefit if people are unlikely to do itĪnyway. Get without the rule, so a rule against a very harmful practice may The benefit is measured relative to the codebase we would Must be large enough to justify asking all of our engineers to The goals of the style guide as we currently see them are as follows: Style rules should pull their weight The benefit of a style rule (some can be), and what sort of argument or alternative would be Serving, it should be clearer to everyone when a rule may be waived If you understand what goals each rule is The fore, we hope to ground discussions and make it clearer to ourīroader community why the rules are in place and why particularĭecisions have been made. There are a few core goals that we believe this guide should The reader is familiar with the language.

Note that this guide is not a C++ tutorial: we assume that Google conform to the requirements in this guide.

The term Style is aīit of a misnomer, since these conventions cover far more than The conventions that govern our C++ code. Style, also known as readability, is what we call Keep the code base manageable while still allowingĬoders to use C++ language features productively. The goal of this guide is to manage this complexity byĭescribing in detail the dos and don'ts of writing C++ code This power brings with it complexity, which in turn can makeĬode more bug-prone and harder to read and maintain. Programmer knows, the language has many powerful features, but C++ is one of the main development languages used by
