
Gofmt No Longer Allows Spaces. Tabs Only - gmjosack
https://code.google.com/p/go/issues/detail?id=7101
======
ahoge
I prefer tabs (tab-size: 4), but I prefer even more if everyone follows the
same conventions.

Dart, for example, uses 2 spaces. When I write Dart code, I use 2 spaces.

And that's the end of that. As history has shown, there is absolutely no point
in discussing this. There is no clear winner.

~~~
MetaCosm
Yep. Asking a developer about style/formatting is an amazing filter if you
have a lot of candidates... the answers I am looking for include "the language
/ platform standard", "the overwhelming most popular standard". The answers I
have gotten have been nothing short of insane at times. I had a guy explain to
me for almost 25 minutes why HIS system is UNIVERSALLY applicable to our code
base, from C and C++ (multi platform) to Python to Makefiles...

------
divoxx
Awesome. The only thing that really matters is to have a convention, and tabs
has been the accepted convention in the Go community since forever.

Changing go fmt to enforce the convention is simply making sure that people
write code the same and frees the developers from the tireless discussion
about which one is better. That alone outweigh any disadvantage of choosing
one or the other.

------
erkose
This is the oldest most persistent argument in programming.

~~~
libria
No, Fitz is not advocating tabs over spaces in coding. He is saying gofmt
loses a large part of its purpose if it does not enforce a particular style,
and the Go devs happen to prefer tabs.

It sounds like he's fine w/ anyone using a tool to format by spaces.

That said, this is quite un-newsworthy.

~~~
gmjosack
I'd say it's newsworthy to large Go shops that use spaces with gofmt and now
have to change indentation in their repos. This isn't insignificant. Also it
requires additional flags for things like blame/diff to ignore whitespace
changes.

~~~
f2f
no such large go shops exist.

~~~
gmjosack
Is it that unbelievable to you that a company that previously used other
languages with spaces for indentation would desire to have a consistent
indentation policy, especially considering that up until now the tooling
supported such desires?

------
AYBABTME
And what's great; no Go developer will notice.

~~~
mahyarm
Their source control will notice.

------
gmjosack
I'm personally in the spaces camp but my favorite point in favor of tabs no
one has mentioned is all of the bytes you're saving. In a large codebase you
can save kilobytes to megabytes by switching from spaces to tabs. :)

~~~
notacoward
Yes, I see the smiley, but I thought it would be fun to measure this effect
anyway. I whipped up a small Python script to measure the potential savings,
and ran it across the 450kLOC GlusterFS codebase. It reported 3.4MB of savings
(both realized and potential because our code isn't as consistent as it could
be). I'm generally in the spaces camp myself, and believe that 3.4MB just
isn't worth worrying about any more (despite being worth ten of the floppies
that were omnipresent even several years into my career), but it's still a
surprisingly high number.

~~~
bingaling
Did you take into account filesystem block size?

------
teddyh
The _right_ way to solve all this tabs/spaces indentation mess would be to use
Elastic Tabstops¹.

1)
[http://nickgravgaard.com/elastictabstops/](http://nickgravgaard.com/elastictabstops/)

~~~
f2f
gofmt already uses elastic tabstops.

~~~
teddyh
To quote [1]:

 _Not really. Elastic tabstops is about enabling variable width fonts to be
used in text (and especially programming) while still lining up tabular
columns. What gofmt does is to use spaces to align columns; a method described
in[http://nickgravgaard.com/elastictabstops/](http://nickgravgaard.com/elastictabstops/)
as a "kludge"._

1) [https://groups.google.com/d/msg/golang-
nuts/93t0LWvHrKM/y6oI...](https://groups.google.com/d/msg/golang-
nuts/93t0LWvHrKM/y6oIIoEZmz0J)

------
zak_mc_kracken
I predict that this change will be reverted in a few months when the Go team
realizes that code is read in a lot of different places, most of which never
display hard tabs correctly.

~~~
silon3
Browser <pre supports tabs and defaults to the value of 8 (as is standard), so
that shouldn't be a problem.

~~~
ahoge
You can also change it to 4 (which is what most editors use by default) via
`tab-size`:

[https://developer.mozilla.org/en-US/docs/Web/CSS/tab-
size](https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size)

------
maxk42
What are the pros and cons of each?

------
angersock
Who actually uses tabs instead of spaces? I'm genuinely curious--one of the
first things pretty much any project I've ever been involved in has been the
setting of tabs characters to become spaces, simply because all text editors
are retarded in this regard. This is quite strange.

~~~
josegonzalez
Unsure if trolling or not. It's quite easy to have your editor represent a tab
character as "n spaces" \- where n is the number of spaces you find pleasing.
In fact, I can't recall a serious editor where this isn't the case.

What issues have you seen with regards to using tabs?

~~~
MBlume
Grabbing some Clojure code because it's nearest to hand.

Look here:
[https://github.com/clojure/clojure/blob/master/src/clj/cloju...](https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L226)

I want the bindings being declared within that let to line up with one
another. the first one immediately follows "(let [" so I need the rest to be
indented six characters past where the let was originally indented. Six, not N
times whatever the tab width happens to be in whichever editor someone's
looking at the code in. This is the problem with tabs.

~~~
gmjosack
The way people solve that is tabs for indentation and spaces for alignment. In
my opinion this is a terrible compromise as mixing tabs and spaces is
sacrilegious.

~~~
msutherl
There is nothing wrong with mixing tabs and spaces. It works great.

~~~
oelmekki
Provided everyone use the same tab width :)

~~~
dTal
Nope, works regardless of tabwidth; that's the point. Tabs for indent (these
change size with tabwidth), spaces for alignment (these don't change so things
stay aligned).

~~~
oelmekki
Oh, you're right. I should have tried it before commenting :)

