I didn’t notice this earlier, but apparently Google’s C++ Style Guide is now public. I think it’s quite good.. acclimating to it wasn’t very hard when I started. Some of the rationales (when you expand the rule on that page) have good food for thought for programmers.
2 comments
Interesting, there are indeed so many ways to do most things in C++ that I appreciate anyone’s thoughtful explanations of why certain features should be avoided. As I began reading it seemed that I already follow most of these conventions, but I have found the following rather long list of exceptions:
- I always declare copy constructors.
- I frequently overload operator==.
- I use std::tr1::shared_ptr to encapsulate almost all data.
- I use exceptions for error handling.
- I use streams for all I/O.
- I use unsigned integral types whenever appropriate.
- I use the .cxx extension rather than .cc.
- I use my own variant of so-called Hungarian notation for variable names.
- I document everything using Doxygen comments.
- I allow code lines to exceed 80 characters when there is not an easy way to avoid this.
- I always give braces their own line.
- I never put whitespace before a keyword / identifier and an open parenthesis, or after a closing parenthesis.
Some of these are simple questions of style, but there are probably a few that expose something I have been doing that is unsafe or inefficient.
This has been exceptionally handy when contributing code to Google open source projects.
In addition, it’s nice to have a well-thought-out document to refer to when in discussion of coding style in other projects (like Mozilla).
Leave a Comment