Why were tabs chosen for indentation?

2,584 views
Skip to first unread message

Carl

unread,
Mar 19, 2017, 4:50:54 PM3/19/17
to golang-nuts
Hi,

This is a question to whoever decided that go will use tabs - team or person:

Could you please explain your reasoning behind the decision?

So far, all my googling has just turned up the what and not the why:

States that tabs are to be used:

Asks the question, but quickly gets off topic without answering it:

So my question is why were tabs chosen? 
I have no preference for tabs vs anything else, but I do respect the go team and the language designers and would really like to know the thinking behind the decision.

Cheers,
Carl

Rob Pike

unread,
Mar 19, 2017, 5:36:06 PM3/19/17
to Carl, golang-nuts
How wide should the indentation be? 2 spaces? 4? 8? Something else?

By making the indent be a tab, you get to decide the answer to that question and everyone will see code indented as wide (or not) as they prefer.

In short, this is what the tab character is for.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carl

unread,
Mar 19, 2017, 5:47:03 PM3/19/17
to golang-nuts, carl...@gmail.com
Exactly what I was looking for. Thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Tim K

unread,
Mar 19, 2017, 7:53:32 PM3/19/17
to golang-nuts, carl...@gmail.com
gofmt documentation says:

Gofmt formats Go programs. It uses tabs (width = 8) for indentation and blanks for alignment.

https://golang.org/cmd/gofmt/

Just curious, any reason why it needs to specify the tab width = 8? Should that be removed if it's not relevant?

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Kevin Malachowski

unread,
Mar 19, 2017, 8:33:11 PM3/19/17
to golang-nuts
I love that Go uses tabs because I use 3 spaces for my tabstop, and very few people share that preference.

Ian Davis

unread,
Mar 19, 2017, 8:44:24 PM3/19/17
to golan...@googlegroups.com
On Sun, 19 Mar 2017, at 09:35 PM, Rob Pike wrote:
How wide should the indentation be? 2 spaces? 4? 8? Something else?

By making the indent be a tab, you get to decide the answer to that question and everyone will see code indented as wide (or not) as they prefer.

In short, this is what the tab character is for.

Please don't take this a criticism of the choice or of gofmt, but purely an observation. It seems to me that this explanation is at odds with the philosophy of gofmt which is that there is a single way to lay out code. The benefits of that are obvious but using tabs erodes it somewhat when you read code on another computer.

I always felt the reason for using tabs was to enable support for non-monospaced fonts and multi-width characters. A tab stop in the traditional sense is a linear position, not a number of characters.

Ian

Wojciech S. Czarnecki

unread,
Mar 19, 2017, 8:59:45 PM3/19/17
to golan...@googlegroups.com

> > On Sun, 19 Mar 2017, at 09:35 PM, Rob Pike wrote:
> > everyone will see code indented as wide (or not) as they prefer.

> Ian Davis <m...@iandavis.com> wrote:
> It seems to me that this explanation is at odds with the philosophy of
> gofmt which is that there is a single way to lay out code.

> The benefits of that are obvious but using tabs erodes it somewhat when
> you read code on another computer.

It is that person who prefers particular tab width who sees code on 'another'
computer. Gofmt makes code 'style' uniform for readability.
Forced tabs make code familiar with indentation one is
accustomed to.


> I always felt the reason for using tabs was to enable support for non-
> monospaced fonts and multi-width characters. A tab stop in the
> traditional sense is a linear position, not a number of characters.

--
Wojciech S. Czarnecki
^oo^ OHIR-RIPE

Axel Wagner

unread,
Mar 20, 2017, 4:45:59 AM3/20/17
to golang-nuts
The "philosophy of gofmt" was to end arguments about how go code should be formatted.
Which gives this thread a special form of irony :)

Dan Kortschak

unread,
Mar 20, 2017, 7:24:52 PM3/20/17
to Axel Wagner, golang-nuts
On Mon, 2017-03-20 at 09:45 +0100, 'Axel Wagner' via golang-nuts wrote:
> The "philosophy of gofmt" was to end arguments about how go code
> should be formatted.
> Which gives this thread a special form of irony :)


People will always adjust their behaviour to minimise the delta on
their dissatisfaction with the world and their personal unhappiness set
point. Sometimes this means complaining about things that don't really
matter.
Reply all
Reply to author
Forward
0 new messages