Poll: Spaces or tabs?
If it didn't matter syntactically with the programming language and there isn't a style guide governing it, do you prefer spaces or tab(s)? Why?
Edit: clarifying here, I'm referring to the characters saved into the file. Specifically multiple ' ' or '\t'. Doesn't matter what you type. If you configure your editor to insert 4 ' ' for each time you press tab. You vote for space.
55 comments
[ 3.3 ms ] story [ 110 ms ] threadNor why style guides recommend it.
Any one have a good reason?
\t int b);
or
\t\t int b);
Because they'll look the same to you, but not to anyone else without 4-space-tabs.
If I type with 4-space tabs:
And then print it with 8-space tabs: but if I had saved the tabs as spaces, it would still line up.You can use spaces only, or you can have a random invisible mish-mash of tabs and spaces.
Nobody EVER gets it right, and if you're coding in something whitespace-sensitive, you're in for a wild ride.
(groan)
http://en.wikipedia.org/wiki/Fewer_vs._less
> The comparative less is used with both count and uncount nouns in most informal discourse environments and in most dialects of English, and in these environments, the word fewer is hardly used at all.
> Less has always been used in English with counting nouns. Indeed, the application of the distinction between less and fewer as a rule is a phenomenon originating in the 18th century.
etc etc.
Yes. The rule is:
"Less" of a continuous quantity.
"Fewer" of a countable quantity.
So "fewer" keystrokes. The issue is clear communications, not rules -- the rules serve the goal, not the reverse.
Goerge W. Bush once said there would be less soldiers in Iraq in a subsequent year. I immediately pictured the same number of soldiers, but each of them smaller.
Again, it's not about correctness, it's about clear communications.
You can't redefine words and then complain when people don't use your new definition.
"Less keystrokes = optmal laziness." is perfectly clear in context. 'Smaller keystrokes' is, in context, nonsensical.
Contradicted by this:
http://grammar.quickanddirtytips.com/less-versus-fewer.aspx
And this:
http://en.wikipedia.org/wiki/Fewer_vs._less
And this:
http://oxforddictionaries.com/words/less-or-fewer
And this:
http://afterdeadline.blogs.nytimes.com/2011/03/01/fewer-vs-l...
A quote from the last link: "The basic rule for precise use of 'less' and 'fewer' is simple (though we slip often). Use 'fewer' with countable, individual things, and 'less' with uncountable amounts, volumes, etc. So: 'I should drink less coffee,' but 'I should eat fewer doughnuts.'"
> 'Smaller keystrokes' is, in context, nonsensical.
Yes -- which is why I posted in the first place.
A space is a space, one character width (when fixed-pitch fonts are used). A tab, on the other hand, is whatever the editor thinks it is, and a given editor can be made to change how it represents a tab (by default eight character spaces).
The above problems become much more severe in languages and environments that honor whitespace -- examples Python and YAML.
There is no excuse for tabs in modern times. They were originally meant to regularize columns on a mechanical typewriter, then they were meant to save memory when memory was precious. Neither of these justifications (no pun intended) exists any longer.
It's no contest -- eliminate tabs.
In your experience, can you give an example of recurring bugs related to not being able to distinguish between tabs and spaces?
Sure -- in Python, a mixture of tabs and spaces. This is certain to result in indentation that looks right to the human, but produces perverse results when interpreted by the language.
> I see tab widths being configurable in editors as a major advantage over spaces.
The sole advantage of tabs is that they can be globally replaced by spaces, after which the program can be analyzed and repaired to undo the damage the tabs produced.
Also, did you think about the above remark? If you change the meaning of tabs in the editor, there's no easy way to let the language know what you decided. The outcome is that the editor operates under one assumption, and the language operates under another.
Python (and Haskell) are pathological cases because the syntax of the language depends on whitespace. There are very good reasons to avoid tabs in those languages. I don't think you'll find many people that disagree with you on that one.
But your argument is that tabs should be abolished, regardless of the language.
So I'd ask: In your experience, can you give an example (in a language that does not care about whitespace) of recurring bugs related to not being able to distinguish between tabs and spaces?
Translation: "If we eliminate any chance that a tab will be misinterpreted, can you think of a case where a tab might be misinterpreted?"
The issue are those cases where tabs do lead to confusion, not where they don't.
This is inconsistent with your initial statement:
> After nearly 40 years' experience in programming, I offer that (as to computer source code) tabs should be outlawed.
You said nothing about "programming languages that make whitespace significant."
Therefore, I was asking why you want tabs outlawed in other languages. If this isn't the case, then we're in agreement---but your initial post was misleading.
If I use tabs, then Python will just consider a line that starts with 2 tabs to be indented one more level than the previous line with 1 tab, and so on. What I set my editor to display the tab as shouldn't affect how the interpreter reads it (unless I mix spaces and tabs, which while I don't think it's likely or common, I do agree you have a point there).
Or did I misunderstand you?
Yes, but that's at odds with how the code looks to a human when both tabs and spaces are used. Remember that I qualified my remark by saying it was about a mixture of tabs and spaces.
The question begins with "If it didn't matter syntactically with the programming language".
Not in the post to which I replied, that was added later -- review the thread.
So I suggest doing spaces except when writing GO, then use tabs.
But one of the things that they say is "people like different styles" presumably meaning that some like four space indents, some like two, and linus likes 8. However that still doesn't address the old bugaboo about indentation vs alignment, which could be thought of as one of the two great unsolved problems in computer science.
I suspect many others are in this boat and it could complicate the poll a bit since it's not specified whether we're voting for what we prefer to use on the keyboard versus what we prefer to actually end up in our files..
This, incidentally, will preserve correct relative indentation regardless of tab settings in editors (it would even work for python, since you only have the first kind of indentation in python given python's indentation sensitivity, but the convention of spaces-over-tabs is so strong in Python that its not worth debating, given how much higher the cost of inconsistency is compared to the cost of choosing the less-ideal option consistently.)
The downside is that different environments (and different languages) will interpret the tab differently. Not so for spaces.
This is not usually an issue unless both tabs and spaces are used in the same file, and that was my qualifier.
Sometimes I might use tab, sometimes I might notice something's off by one and use a space (for right or wrong, habits + muscle memory etc.) I also use code from other developers who may be even more inconsistent or pick one over the other.
If everyone just uses spaces - as in common in the worlds I work in - a lot of the above issues are prevented.
My editor Arachnophilia has the option to generate spaces when the tab key is pressed. I'm sure some other editors work that way too.
What I'm talking about is that some crazy people think tabs are identical to, and indistinguishable from, spaces; just quicker to type. They'll do evil stuff like mandate a width for the tab character, then alternate tabs and spaces at different levels of indentation. (One indent, 4 spaces; two indents: one tab; three indents, one tab and 4 spaces). If I recall correctly, this is one of the auto-format styles you can choose by default in Eclipse. I have never understood why people do it. I think they're just sadists, or it's a clever way to make code read-only.
I prefer indenting with tabs, but if you're indenting with tabs while requiring a specific tab width - for any reason - you are part of the problem and I wish your code a thousand disk failures.
If one dev uses tabs and another uses spaces then, depending on the tab width they have configured, the files indentation can look completely wacked.
100% spaces for me.
http://editorconfig.org/
Personally, I don't see any advantage for spaces and no any disvantage for tabs.