Favorite Social Media Timesink
When you take a break from work, where are you going?
Video clips on TikTok/YouTube
X, Bluesky, Mastodon et al...
Web surfing
I do not get distracted by petty amusements
Software Development

Spaces vs. Tabs: A 20-Year Debate Reignited by Google’s Golang

Sep 17th, 2016 9:29am by
Featued image for: Spaces vs. Tabs: A 20-Year Debate Reignited by Google’s Golang

Geeks have been choosing sides for the past 16 years — should programmers indent their code using spaces or tabs? But now the infamously trivial flame war has been given a new prominence by a study from Google — possibly inspired by the dialogue in a recent episode of HBO’s Silicon Valley.

“Truth be told, I do have a slight preference for tabs. But that’s only because I’m anal and because I prefer precision.”

“Well, not to pick a fight here, but if you really care about precision, wouldn’t you use spaces? But whatever, once it goes through the compiler, it’s the same thing, right…?”

“If it’s all the same, why not just use tabs?”

“Because it could look different on other people’s computers.”

“Tabs create smaller file sizes, all right…? I mean, why not just use Vim over Emacs?”

“I do use Vim over Emacs.”

“Oh, god help us!”

Finally this year — right before the Labor Day weekend — Google’s developer advocate decided to weigh in. “We are going to parse a billion files among 14 programming languages to decide which one is on top.” They crunched files from the top 400,000 GitHub repositories, looking at only files of code written in the top languages — and their chart showed that spaces were by far the most popular method of indenting, in every language. Except Go and C.

“Confirmed, Go is the language of the future,” joked one commenter on Reddit.

“It also automatically formats your source code,” countered another programmer. “I use spaces, and it spits out tabs!”

And on Twitter, one developer joked the essay had only created another controversy. “The new discussion is now ‘what the hell is wrong with Go?‘”

At least one Canadian engineer applauded the effort that Google put into settling the question.

But in the end, Google failed to bring peace to the developer world.

When someone referred Castillo to Google’s analysis, he simply added “I knew that. And yes, they all are 100% wrong.”

“What is this madness,” tweeted cloud engineer Ed Morgan.

“Madness everyone knows tabs are better!” replied a London-based NetApp maintainer.

“This is disgusting,” tweeted one freelance web designer in the U.K.

And it didn’t end there. Google’s post soon went viral, drawing 1,620 comments on Reddit, and also turning up on Gizmodo, Slashdot, and Hacker News. “After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observation and it’s what resonates with me the most,” wrote one programmer on Hacker News.

“In an ideal perfect world, _all_ of programmers and _all_ text editor tools would use tabs specifically for indentation and spaces specifically for alignment. But, we don’t live in that perfectly coordinated world so spaces maintains the most fidelity — at the expense of programmers not being able to instantly customize the indentation from widths of 2,4,6,8.”

Have geeks really been arguing about this for 20+ years? Looks like it. It was already being described as an “interminable argument” by Jamie Zawinski, one of the coders on the early Netscape Navigator browser — back in 2000. His post explained how to configure two Linux text editors (Emacs and Vi) to change the tabs to various widths. (“So go forth and untabify!”)

Merrily we rolled along, and in 2004, a post on the Microsoft Developer Network took up the very same issue, noting that some people combine spaces and tabs, and arguing that they’ve actually staked out a fourth position: coding tools should be configurable to display each user’s preferred view, while saving code in accordance with an agreed-upon set of rules. But not everyone was so open-minded. In 2009, Jeff Atwood, one of the co-founders of Stack Overflow, wrote a blog post called Death to the Space Infidels!. He lobbies for his position by citing the beloved 1984 book Code Complete.

“Our studies support the claim that knowledge of programming plans and rules of programming discourse can have a significant impact on program comprehension… It is not merely a matter of aesthetics that programs should be written in a particular style… programmers have strong expectations that other programmers will follow these discourse rules. If the rules are violated, then the utility afforded by the expectations that programmers have built up over time is effectively nullified.”

And Atwood cites more experiments — one from the early 1970s — which found that information is retained better when it’s arranged in a meaningful order. “So yes,” Atwood concludes, “absurd as it may sound, fighting over whitespace characters and other seemingly trivial issues of code layout is actually justified. Within reason of course — when done openly, in a fair and consensus building way, and without stabbing your teammates in the face along the way.”

Four years later, the question turned up in the heart of geek nation — in a discussion on Stack Overflow.

“Spaces,” reads one argument. “A tab could be a different number of columns depending on your environment, but a space is always one column.”

“Tabs,” reads the counter argument. “They’re a character specifically meant for indentation. They allow developers with different preferences in indentation size to change how the code looks without changing the code”

So there!

Silicon Valley - spaces vs tabs

But the tabs part of the page ultimately strikes a conciliatory note. “Of course, consistency matters more than either one, and a good IDE makes the differences negligible.” But why spoil a good argument? “That said, the point of this thread is to be a holy war, so…”

And Jeff Atwood himself seems to agree — to a point. Back in 2009, he wrote “It doesn’t actually matter which coding styles you pick. What does matter is that you, and everyone else on your team, sticks with those conventions and uses them consistently.” But he couldn’t resist adding one more sentence.

“That said, only a moron would use tabs to format their code.”


Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.