opensource.google.com

Menu

Stylish C++ Code

Monday, June 30, 2008



Even when you speak the same language as someone else, you may find differences in spelling, pronunciation, or even vocabulary. While the difference between "color" and "colour" isn't likely to confuse anyone, you might run into trouble if your audience doesn't realize that a car's "boot" is the same as its "trunk." Some of us are still trying to figure out whether we wait "on line," "in line," or whether we simply "queue up."

Computer languages are no different in this regard. When you're working on a large software project, how you express something may be a vital part of the code. At Google, we've adopted a set of conventions intended to give all contributors a common coding vocabulary. This ensures that it's as easy as possible to understand code quickly when reading it, both for the original author and later reviewers. Our coding style covers many areas from formatting (we prefer two-space indentation) to use of language and library features (we only allow multiple interface inheritance, not multiple implementation inheritance).

When we release our own code to the public at Google, we're not just sharing our work with the world, we begin to accept contributions to that code base from the public. Naturally, our own code follows our style guidelines, but until now, contributors to Google Open Source projects haven't had a reference for the Google coding style. This has led to frustration for coders and reviewers, and we believe that it's unfair to ask contributors to use a set of rules that haven't been defined for them. With the recent release of the Google C++ Style Guide, we're changing that.

We don't think that our own style of C++ is the only way to write C++, or even necessarily the best, but we do believe that a style guide to define readability and consistency is a tool we can all use to improve software quality. If you're contributing to a Google Open Source project, you may be referred to our guide sometime soon. We're proud of our Open Source contributions, and we're glad we can make life easier for all of our community contributors.
.