go-essentials icon indicating copy to clipboard operation
go-essentials copied to clipboard

The essential reading list for Golang developers

Go Essentials

Reading, and understanding, Golang's "Effective Go" document is absolutely essential for writing clear, idiomatic Go code.

Rob Pike's article "Go at Google: Language Design in the Service of Software Engineering" is a must read for learning Go. He explains the very real problems they were having at Google which lead them to create Go.

The book "The Go Programming Language" by Alan Donovan and Brian Kernighan is a must read. It is assumes you already know how to program so it is very concise while still being very readable. Make sure you read both Chapter 8 "Goroutines and Channels" and Chapter 9 "Concurrency with Shared Variables" carefully. Overall, one of the best programming books I have read.

Naming

Naming is always an important topic. In Go, understanding how package names are used is key to picking good names for your own packages. The Go Blog's article "Package Names" is worth reading at least twice.

Andrew Gerrand's "What's in a name?" talk is also a good reference for Go's naming conventions including "length of variable names". Specific slides cover naming of:

Pointers

Understanding pointers is critical to writing clean and efficient Go code. Unfortunately, pointers are difficult to understand.

Bill Kennedy's four part series on "the mechanics and design behind pointers, stacks, heaps, escape analysis and value/pointer semantics in Go" is a must read.

  1. Language Mechanics On Stacks And Pointers explains the basics of pointer mechanics using two examples in which a value is shared down a goroutine's stack. Bill steps through each of the examples and provides figures visualizing the layout of the stack at each step.

  2. Language Mechanics On Escape Analysis focuses on the heap by using an example in which a value is shared up a goroutine's stack. Again, Bill steps through the example and provides figures visualizing the memory. Along the way, Bill talks about the readability of code when returning a pointer from a function and how the compiler performs static code analysis to determine if a value can be placed on the stack frame for the function constructing it, or if the value must “escape” to the heap. He also shows how to see the decisions the compiler is making for each of these values.

  3. Language Mechanics On Memory Profiling shows other scenarios that can cause values to escape. Bill does this by debugging a program that is allocating in surprising ways. This article shows how to use a standard benchmark test and the memory profiler to find and fix a memory and performance issue.

  4. Design Philosophy On Data And Semantics is an absolute must read. When you declare a new data type, you must decide whether to use value or pointer semantics for the data type. Bill provides "semantic guidelines" to help with this decision.

  5. Bonus: Bill's For Range Semantics article explores how the for range statement in Go provides both a value and pointer semantic form. He also shows a simple example of how easy it is to mix these semantics and the problems it can cause.