5 ms·
Gofmt No Longer Allows Spaces. Tabs Only
- gmjosack 12y agoI'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 12y agoYes, 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 12y agoDid you take into account filesystem block size?
- zak_mc_kracken 12y agoI 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.
- mseepgood 12y agoI've read a lot of Go code in many different places during the last years, all with tabs, and I did not have any problems.
- silon3 12y agoBrowser <pre supports tabs and defaults to the value of 8 (as is standard), so that shouldn't be a problem.
- ahoge 12y agoYou 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
- erkose 12y agoThis is the oldest most persistent argument in programming.
- nickporter 12y agoI wonder if other professions have similar arguments.
- nmb 12y agoI got into beekeeping recently, and it's like this, except applied to everything.
- maxk42 12y agoSo... tabs or spaces?
- adamnemecek 12y agoCan you give some examples? I'm really curious.
- nmb 12y agoEasily. Just get any two beekeepers to talk to each other and you'll find plenty of examples. Some common ones: - Whether to use a [queen excluder](http://en.wikipedia.org/wiki/Queen_excluder http://en.wikipedia.org/wiki/Queen_excluder) or not. - What [kind of hive](http://www.beethinking.com/pages/what-is-the-best-bee-hive http://www.beethinking.com/pages/what-is-the-best-bee-hive) to use, even. - If using a Langstroth hive, whether to use [10-frame or 8-frame boxes](http://www.beesource.com/forums/showthread.php?291373-10-frame-vs-8-frame http://www.beesource.com/forums/showthread.php?291373-10-fra...). - How/when/whether to [feed your bees](http://www.bushfarms.com/beesfeeding.htm http://www.bushfarms.com/beesfeeding.htm). However, despite having all these disagreements, it's an incredibly friendly community. It's expected that anyone you meet will do things differently from you, so people swap advice and adopt things that work with their style. Edit: whelp, markdown doesn't work here but I'm too lazy to change it.
- angersock 12y agoWho 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 12y agoUnsure 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?
- angersock 12y agoOften different editors on a project (hell, even between computers for the same user) may display the same file different ways, and you almost always end up with weird mixes of spaces/tabs when indenting things (especially if you're super picky like I can be and really, really care about things lining up). Simply having the editor expand tabs (to whatever people agreed on, usually 4 for C/C++ that I've seen) and save spaces, always, makes life simpler. EDIT: See Grandpa Zawinski's post on same: http://www.jwz.org/doc/tabs-vs-spaces.html http://www.jwz.org/doc/tabs-vs-spaces.html
- dTal 12y agoI hate that Zawinsky post. At the top, he says "I'm trying to avoid espousing my personal religion here, I just thought it would be good to try and explain the various sects." At the bottom, after thoroughly missing the point about semantic indentation, he says "So go forth and untabify!"
- Glyptodon 12y agoI'm not sure if there's an "issue" with tabs, but I have to agree that I pretty much never come across tabs in any of the languages I use regularly and find it jarring when I do so despite the obvious theoretical benefit of flexible tab widths enabling user preference. I can't come up with a particularly good reason for it, but I'm so used to spaces at this point that tabs feel very wrong. If anyone else has a good explanation I'd love to hear it.
- AYBABTME 12y agoAnd what's great; no Go developer will notice.
- mahyarm 12y agoTheir source control will notice.
- teddyh 12y agoThe 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 12y agogofmt already uses elastic tabstops.
- teddyh 12y agoTo 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/y6oIIoEZmz0J https://groups.google.com/d/msg/golang-nuts/93t0LWvHrKM/y6oI...
- maxk42 12y agoWhat are the pros and cons of each?
- divoxx 12y agoAwesome. 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.
- ahoge 12y agoI 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 12y agoYep. 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...