Indentation in Go: tabs or spaces?

Is there a standard Google Go coding conventions document somewhere that states whether tabs or spaces are preferable to indentation in Go source code? If not, then which (statistically) more popular option?

  1. What is the official recommendation? (if there's)
  2. Which choice is more popular?
+91
formatting indentation go
Sep 30 '13 at 12:48
source share
2 answers

The official recommendation is to format your code with

go fmt 

or directly using the gofmt command

 gofmt -w . 

You can read about it here on the golang.org blog or from Effective Transition :

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

+153
Sep 30 '13 at 12:49 on
source share

According to http://golang.org/src/cmd/gofmt/doc.go , the default values ​​are:

EDIT: the original answer below is now incorrect. The correct section of the linked source file (current 07/25/2014):

Gofmt Go program formats.
It uses tabs (width = 8) for indents and spaces for alignment.

Original answer (deprecated):

 Formatting control flags: -comments=true Print comments; if false, all comments are elided from the output. -tabs=true Indent with tabs; if false, spaces are used instead. -tabwidth=8 Tab width in spaces. 
+19
Sep 30 '13 at 12:52
source share



All Articles