Getting Started with Go

May 2018

If you’re starting a new project or a job that requires knowing Go, here’s an opinionated learning plan that will get you ready in a hurry. If you’re exploring Go out of idle curiosity, this probably isn’t the plan for you—there are plenty of excellent videos and conference talks with a better balance of entertainment and technical content.

Learn the Language

You don’t need a local Go installation to get started - you can learn the language and start writing code in your browser.

  1. Watch an hour-long talk by Rob Pike, one of the core authors, for a sense of Go’s goals and aesthetic.
  2. Do the entire Tour of Go and read How to Write Go Code.
  3. If you’re writing Go professionally, join the Gophers Slack and the golang-nuts mailing list. If that sounds like too much, at least join golang-announce.
  4. Install Go using your typical package manager. We’ll revisit this later.
  5. Install and get used to gofmt, Go’s code formatter. Use it on all your code.

After those three steps, spend some time writing a bit of toy code.

Learn the Idioms

As a community, Go programmers tend to prefer strong conventions over freedom of expression. Before you start writing Go professionally, get acquainted with the community norms.

You don’t need to read these documents in one sitting, but you should read them…don’t just skim the headings and move on.

  1. As soon as you’ve read and written a little code, read Effective Go. This is canonical advice, and everything in it is widely accepted in the Go community.
  2. For authoritative but slightly less canonical advice, browse the Go team’s common code review feedback and their guidance on package names.
  3. Learn the common idioms for working with slices.
  4. Read some core material from the Go blog. Start with the overall approach to concurrency and error handling (including part two), then move on to Go’s take on try-catch-finally blocks.
  5. Unit testing is built into the language, so get familiar with the standard library’s testing package, sub-tests, the race detector, and how to measure code coverage.
  6. Documentation generation is also built into the language—familiarize yourself with the comment conventions and testable examples. Bookmark godoc.org pkg.go.dev, which serves documentation for the standard library and all open-source Go packages.

Learn the Details

Once you’ve picked up the basics and some common idioms, dive a little deeper.

  1. At this point, it makes sense to stop relying on your package manager’s Go distribution. Instead, use upstream directly—it’ll be much easier to test beta releases and debug on older compilers. I use Travis CI’s gimme script. It’s a plain shell script, and it’s the same script that manages Go versions in Travis builds.
  2. Learn the details of Go constants, strings, slices (part two), and maps.
  3. Grok some more advanced concurrency patterns, including pipelines and cancellation.
  4. Gophers solve lots of problems by generating code, so read a little about the go generate command.
  5. Try profiling a running program.
  6. Read about the design of the garbage collector.
  7. Browse a bit of the language specification. It’s very readable, so don’t be afraid to consult it if you have specific questions later on.

If you’re done with all that and still want more material, work your way through The Go Programming Language and take Bill Kennedy’s Ultimate Go class. Both resources are long but worthwhile.