About Archives Tags RSS
April 30, 2009
1:30 am PST
2 comments
Tags: ,

Stylish

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

1 Chad Hogg { 04.30.09 at 6:14 am }

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.

2 Ted Mielczarek { 04.30.09 at 9:48 am }

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

You might also want to register or log in