Pocket Gophers

Idiomatic Go


What is idiomatic Go? It's frequently asked, but doesn't have an easy answer. Part of the problem is that we are still figuring it out. This is partly because Go is a young language. As the language and community matures, so will the idioms.

Be aware that idioms are more like guidelines than rules. Working code is more important than idiomatic code. Since idioms are sort of a shared experience, something that is not idiomatic is not necessarily wrong.

Since there isn't a definitive answer, I have collected relevant references.

Accept interfaces, return concrete types new

Craig Brookes 2016-11-02

Explains the idiom is and why you should follow it.

Code Review Comments

A collection of common things found during code reviews. The shorthands explained show the idiomatic way to do things.

Effective Go

Tips from the Go team for writing clear, idiomatic Go code. This is essential reading and has not only the idioms, but also some of the thinking behind various features.

Go Patterns new

Tamer Tas

A curated collection of idiomatic design & application patterns for Go language

Go Proverbs

Simple, poetic, and pithy sayings collected by Rob Pike to explain Go in a deep, but easy to remember way. Truly understanding and applying them will bring you closer to mastering Go.

Go and the Zen of Python

Andrew Gerrand

Comparison between Go and The Zen of Python.

Go by Example new

Teaches Go with annotated examples that often discuss what is idiomatic.

Idiomatic Doc Comments: Document Your Function, Not Your Function Signature new

Katrina Owen 2015-10-14

Describes, by example, how to write helpful comments for Go functions.

Idiomatic Go

Dmitri Shuralyov

A supplement to Code Review Comments, this lists idioms backed with convincing rationales and references.

Idiomatic Go Readability


Practical experience and tips for idiomatic Go readability. Both manual and automated approaches are discussed.

Idiomatic Go Tests new

Craig Brookes

Explains, with examples, what the author thinks idiomatic testing in Go is.

Idiomatic Go Tricks new

Mat Ryer video slides 2016-08-18

Some everyday tips and tricks that will have you speaking Go like a native.

Itty Bitty Go Idiom: If Without Else new

Katrina Owen 2015-10-16

Explains why there are idioms and that in Go you will commonly see if statements without else clauses.

Things I learned teaching Go

Francesc Campoy Flores 2014-10-10

Its better because its what other people in the community expect.

Experiences from learning several human languages and teaching Go leads to a practical discussion of idioms.

What is idiomatic Go?

A discussion started when an otherwise working codebase was bashed as unidiomatic. The responses show how idioms can both help and hurt a community.

When in Go, do as Gophers do

Fumitoshi Ukai 2014-11-30

Examples of idioms learned by reviewing Go CLs at Google. As a Go Readability Approver, the presenter reviewed ~200 CLs over the course of a year and shares what was learned.

As I find more references, I will update this page. To be notified when this page is updated, please subscribe.

Dig into the Fundamentals of Go

Subscribe to receive a weekly email covering a Go fundamental. Be it the language, its tooling, or its packages, you will learn what you need to know.