Previously I’d mentioned a style guide from Google that covered shell scripts. Turns out they have a style guide for just about everything – https://github.com/google/styleguide:
“Style” covers a lot of ground, from “use camelCase for variable names” to “never use global variables” to “never use exceptions.” This project holds the style guidelines we use for Google code. If you are modifying a project that originated at Google, you may be pointed to this page to see the style guides that apply to that project.
Our C++ Style Guide, Objective-C Style Guide, Java Style Guide, Python Style Guide, Shell Style Guide, HTML/CSS Style Guide, JavaScript Style Guide, AngularJS Style Guide, Common Lisp Style Guide, and Vimscript Style Guide are now available. We have also released cpplint, a tool to assist with style guide compliance, and google-c-style.el, an Emacs settings file for Google style.
2 replies on “Google Style”
At first I was incredulous after reading “never use exceptions.” After reading through their guide (the C++ one; in Java they do use exceptions) it ends up being a pragmatic reason and not a philosophical one. They had coded themselves into it basically (an overuse of error codes.) They even state: “Things would probably be different if we had to do it all over again from scratch.”
While checked exceptions can be overused (some languages do not have this like C#, Java does), they do have a use. Plus unchecked exceptions (runtime) are a whole lot easier to create maintainable code then without (given a good-to-great programmer.)
Style guides are important for consistency of code. Every company should have them. I use them for the projects that I am on (of course I created them so I do have some bias). It helps later on, especially if you bring in another programmer, to keep maintainable and consistent code (of course you do need informal/formal code reviews as well.)
Well, at least you have no one else to blame 🙂 Given enough developers there will always be disagreements about style.
The biggest help to having a style guide is having an automated tool that checks code against the guide rules.