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¶
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.
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¶
A curated collection of idiomatic design & application patterns for Go language
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¶
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¶
Describes, by example, how to write helpful comments for Go functions.
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¶
Explains, with examples, what the author thinks idiomatic testing in Go is.
Idiomatic Go Tricks new¶
Some everyday tips and tricks that will have you speaking Go like a native.
Itty Bitty Go Idiom: If Without Else new¶
Explains why there are idioms and that in Go you will commonly see if statements without else clauses.
Things I learned teaching Go¶
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¶
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.