Indentation in Go: tabs or spaces?

Erik Kaplun picture Erik Kaplun · Sep 30, 2013 · Viewed 71.8k times · Source

Is there a standard Google Go coding conventions document somewhere that sets whether tabs or spaces are preferred for indentation in Go source code? If not, what is the (statistically) more popular option?

  1. What is the official recommendation? (if any)
  2. What is the more popular choice?

Answer

ANisus picture ANisus · Sep 30, 2013

The official recommendation is formatting your code with

go fmt

or using the gofmt command directly

gofmt -w .

You can read more about it here on the golang.org blog, or from the Effective go document:

Indentation
We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.