The Go Style Guides

How to master the Golang Style with the market leading companies (and the community)

The best Golang Style Guides you should be familiar with.

Google: Go Style

Google has a set of styleguides for the languages used in their projects. The Go is one of them. This is the place where you should start your styleguide journey.

The Go Style document is divided into three parts:

As we can read on their page, the purpose of the mentioned documents are:

  1. The Style Guide outlines the foundation of Go style at Google. This document is definitive and is used as the basis for the recommendations in Style Decisions and Best Practices.

  2. Style Decisions is a more verbose document that summarizes decisions on specific style points and discusses the reasoning behind the decisions where appropriate. (...)

  3. Best Practices documents some of the patterns that have evolved over time that solve common problems, read well, and are robust to code maintenance needs. (...)

Every part contains a short introduction and examples in a formula of Good / Bad usage - sometimes it's only Good or only Bad, it depends.

The Style Guide is quite concise, while the latter two are more content-rich. Reading them once will open your eyes on the idea of the language. Keeping them as bookmarks or in the Tab Group will allow you to quickly become a style expert. All the docs are in English.

Uber: Style Guide

The Uber Go Style Guide is in a form of a one, huge markdown in a Github repository Unlike the Google Go Style, this one has been translated by the community into other languages. It also uses the Good / Bad example formula, but these are juxtaposed horizontally, which makes them easier to understand and spot the differences.

And since the Github is the hosting platform, it respects your favorite theme, which is dark one in my example.

Compared to the Google's one I have a feeling like the Uber's is focused more on the practical examples.

It's worth to mention that they try to keep the styleguide up to date:

We aim for the code samples to be accurate for the two most recent minor versions of Go releases.

Go Wiki: Go Code Review Comments

For sure you're doing a lot of code reviews and sometimes you feel like "I need to explain this? Again?"

Using the Go Wiki: Go Code Review Comments you can do your whole code review only pasting links. It really speeds up the whole process. It cuts the discussions, because someone already discussed it.

This is not a typical styleguide:

This is a laundry list of common style issues, not a comprehensive style guide.

Url or URL? Id or ID? No more discussions on that! Initialisms already solved!

Empty slices declaration? Here you are!

It doesn't have a one consisten formula during the whole document, but it does contain all the informations needed to explain why something should or should not be implemented in a specific way.

Definitely would recommend this one!

Effective Go

This document is not a styleguide per se, but more like a set of tips on how to use Go and shows the way of thinking in that language.

This document gives tips for writing clear, idiomatic Go code. It augments the language specification, the Tour of Go, and How to Write Go Code, all of which you should read first.

The most important part is that this document is kinda old:

This document was written for Go's release in 2009, and has not been updated significantly since.

The format is not as clear as in the previous ones, you may feel overwhelmed by the wall of text, but it is still a solid portion of Golang basics.

It's good to know that it exists and in case of doubts scan it for needed information.