The war of the whitespaces rages on among programmers

The battle among developers over the choice of tabs vs. spaces for indentation isn’t close to being decided

Closeup of a tab key on a keyboard
Kai Hendry

Last week, Stack Overflow published the results of its annual survey of software developers. It was filled with many interesting findings, regarding things like developer pay, preferred technologies, job satisfaction, and even caffeine consumption. However, to me, the one takeaway for me from the survey and, in particular, the subsequent discussion of it among developers, was that the age old debate among programmers over the use of tabs versus spaces for indentation continues to rage on like a five-alarm fire.

More than 26,000 developers participated in the Stack Overflow survey, which was conducted over a two week period in February. The survey produced some interesting findings for a wide range of topics. For example, 32% of respondents said they were full-stack developers, 42% reported being self-taught, and 36% said they love their jobs.

Here, however, was the result that piqued my interest: 45% of respondents said they prefer tabs over spaces for indentation, while 34% preferred spaces. Interesting! So, tabs have finally won the war, right?

Well, not so fast, tab-vocates. First of all, this wasn't a scientific survey whose results can necessarily be extrapolated to the general developer population. Second, the Stack Overflow team noted that users with higher Stack Overflow reputation scores (who are presumably older and more experienced developers) tended to prefer spaces over tabs. Specifically, respondents with a reputation over 10,000 preferred spaces to tabs by a ratio of 3-to-1. So, while the survey suggests there’s a generational or experiential divide over tabs vs. spaces, it’s clear that the fight isn’t over just yet.

As further evidence of the ongoing debate over the choice of whitespace character for indentation, I present the subsequent discussion on Slashdot about the survey results. Hundreds of comments were offered and, based on my informal tallying of the subject of each comment on Slashdot, tabs vs. spaces generated, by far, the most discussion. I counted roughly 140 comments about tabs vs. spaces, compared to 20-some about the age distribution of respondents and 15 about the gender imbalance among programmers (92% of survey respondents were males). There were also a handful of comments about other findings from the survey. Clearly, tabs versus spaces still touches a nerve among many programmers more than many other topics.

The debate among the Slashdot respondents about tabs vs. spaces was quite healthy, with many people weighing in on both sides of the issue. Those in favor of spaces often claimed that using tab characters for indentation wreaks havoc with code display.

“Because in every project that uses tabs,
The code is inevitably
       littered with
       the occasional
 line that does not line up with the others
       for no apparent reason.”  Jeremi

“Tabs are fine but unless you and your team have a lot of discipline, it can result in a huge mess. Spaces are much easier to manage.”  GuB-42

“If you edit code on unix tabs are a nightmare.” Anonymous

Those who prefer tabs, on the other hand, often commented that the tab character is the more logical choice for indentation and that highly configurable, modern-day code editors can eliminate display issues. Many also mentioned that spaces can introduce their own variability.

“You know how people say ‘use the right tool for the job’, well tabs are designed for indentation. So use them, rather than bodge some artificial implementation using an arbitrary number of spaces.” gbjbaanb

“Tabs were more likely to cause problems in the old days, when editors did things that were ridiculous like expand them to 8 spaces. Nowdays with everything configurable, it isn't much of an issue. The reason why the older more experienced people prefer spaces is that they learned to dislike tabs in the bad old days. In 10 years that argument will be dead with tabs winning.” AuMatar

“Even if you get a ‘spaces’ person, try to get them to agree on the number of spaces. A coworker loves 2 spaces which is flat out wrong to me. Too hard to read. I've met people into 3 or 4 spaces.” affer1

Unfortunately, we don't know the age or experience of Slashdot commenters (aside from the few who volunteered the information), so I couldn’t tell whether the divide was again along age and experience lines. What’s clear, though, is that battle between advocates of tabs and spaces is still quite lively. Expect the war to continue for the foreseeable future.

This story, "The war of the whitespaces rages on among programmers" was originally published by ITworld.

Copyright © 2015 IDG Communications, Inc.

It’s time to break the ChatGPT habit
Shop Tech Products at Amazon