11 points · by hboon · 13y ago · 53 comments
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.
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?
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?
The question begins with "If it didn't matter syntactically with the programming language".
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.
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.
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..
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.
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.)
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.
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.
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.
Nor why style guides recommend it.
Any one have a good reason?
void function_with_lots_of_arguments (int arg_a,
int arg_b,
int arg_c);
If I was to use tabs and someone had a different tab width to me, they might end up with: void function_with_lots_of_arguments (int arg_a,
int arg_b,
int arg_c); class Foo
{
\tint bar(int a,
\t int b);
};\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:
username admin
port 22
importance 3
And then print it with 8-space tabs: username admin
port 22
importance 3
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.
Personally, I don't see any advantage for spaces and no any disvantage for tabs.
(groan)
> 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.