gofmt, indent with space feature deliberately removed?

1,267 views
Skip to first unread message

Tong Sun

unread,
May 15, 2015, 9:47:10 PM5/15/15
to golan...@googlegroups.com
I always use 

 gofmt -w -tabs=false -tabwidth=2 src

to format my code. But I found the above options that I used to use gone from go 1.3 onward.

In trying to find the answer myself, I've gone through every argument posted in

It seems that google/go team is so strongly oppose using tab stops shorter than 8, or use spaces instead of tabs, that the "-tabs=false -tabwidth=x" feature is now deliberately removed. Is that so? 

Just want to confirm that, instead of waging another round of tab/space war, because enough have been said in the above thread. 

Just one thing, will gofmt touch the spaces that I use in my comments and turn them into tabs? 

thx

Caleb Spare

unread,
May 15, 2015, 10:03:27 PM5/15/15
to Tong Sun, golang-nuts
You seem to have double-posted.

But I found the above options that I used to use gone from go 1.3 onward.

​Yes, this option was removed since tabs are the gofmt standard.

It seems that google/go team is so strongly oppose using tab stops shorter than 8, or use spaces instead of tabs,

​The reason to prefer spaces over tabs is precisely to allow the user to use whatever tab width they desire. "Tab stops" is a property of your editor; you can change the represented tab width to whatever number of spaces you desire. Many people use 4-space tabs; I actually use 2-space tabs.

But if you read that thread, you have seen these points several times already, so I guess you don't find it convincing.

Just one thing, will gofmt touch the spaces that I use in my comments and turn them into tabs?

It will change the space at the front of the line to tabs to match the surrounding code.

-Caleb​
 

 

Tong Sun

unread,
May 15, 2015, 10:24:12 PM5/15/15
to Caleb Spare, golang-nuts
Thanks Caleb.

On Fri, May 15, 2015 at 10:02 PM, Caleb Spare <ces...@gmail.com> wrote:
> You seem to have double-posted.

I found I missed the very important keyword in the subject right after
I posted the first one, so I have to delete it and repost again.
Sorry.

> The reason to prefer spaces over tabs is precisely to allow the user to use
> whatever tab width they desire. "Tab stops" is a property of your editor;
> you can change the represented tab width to whatever number of spaces you
> desire. Many people use 4-space tabs; I actually use 2-space tabs.

Ha, glad to see that you use 2-space tabs as well.

> But if you read that thread, you have seen these points several times
> already, so I guess you don't find it convincing.

Honestly, not quite. That argument comes from and is for people living
their lives using editors or IDEs, whereas I live in the command line
world most of the time, so cat/less/grep etc are the tools I use much
more often then spinning up an editor or IDE. Tab stops is 8
everywhere else, so I won't config my xterm's tab stop to 2 just for
go.

Anyway, I see the decision as a political decision, so won't argue with it.

Dave Cheney

unread,
May 15, 2015, 10:33:36 PM5/15/15
to golan...@googlegroups.com
Formatting is always a decision made by humans for humans -- machines don't care, it's all whitespace to them.

Seth W. Klein

unread,
May 19, 2015, 2:58:41 PM5/19/15
to Tong Sun, golang-nuts
If you use the command line to view source code frequently, may I suggest
creating an alias for expand?

expand -t 2,4,6,8,10,12,14,16,18,20 example.go

P.S. After using eight spaces in Go for some time, I’ve settled on six and
quite like it!
> --
> 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...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages