A Weblog by Ben Goodger

August 8, 2009

I noted with some interest this thread over at mozilla.dev.platform. The Mozilla codebase has historically included a variety of different coding styles, since style for a given file was left up to the person writing the code. The discussion caused me to reflect a little about what we’ve been doing in Chromium, especially since I spent a number of years working in the Mozilla codebase (at times contributing  a few strange experimental styles).

The Chromium project, having had the luxury of a clean start, decided to inherit its coding style guidelines from Google. We tend to use C++ for most of the application code except for the Mac front end, which uses Objective-C, for which Google has another style guide. We prefer not to fork third party components but rather develop improvements to them “upstream” in their respective projects, which retain their own style. The most notable of these is WebKit.

In the beginning, I found several aesthetic aspects of the Google C++ style not to my taste. However in time as the project has grown I found that having a uniform style across the entire codebase to be very soothing. You can go from user interface code to the bowels of the network stack and find the same style. It requires fewer subtle context switches. Because the Google C++ style tends to be very specific about a great many things, the areas where it is silent stand out more when there are variances. We’ve tried to document where as a project we’ve filled in some of these gaps.

One of the interesting things about the Google C++ style guide (the one I am most familiar with) is that in many cases it goes beyond the aesthetic, covering use of language features. Other projects like Mozilla cover this in their portability guidelines, but the Google C++ style guide makes recommendations for other reasons too. For example, multiple inheritance is generally banned, because it is easily misused to create spaghetti object hierarchies that are not easily comprehendable. In fact, more than a few of the style guide sections echo tips from Scott Meyers’ excellent “Effective C++”.

Having as large a style guide as we do, there do tend to be a lot of code review comments about conforming to it. Rather than being nit-picking though that obscures the larger benefit of the work, I actually think it serves that exact purpose - the larger benefit. We are mindful that our ability to rapidly prototype and ship new ideas is key to our relevance, and as such maintaining good hygeine is a key component of that. We want new-comers to get started quickly and old-timers to pursue larger changes efficiently. In the end, in my opinion it feels that the greater good of a uniform style far outweighs the value of an individual developer being able to use their preferred style.

Comments

Comments are Closed