10 ms·
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.
- hboon 14y agoI've never understood what are real good reasons to use spaces if it isn't existing code or there's a style guide recommending it. Nor why style guides recommend it. Any one have a good reason?
- udp 14y agoAt least in C, I like to line things up sometimes: 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);
- wolfgke 14y agoIn this case you use spaces for the parts that shall be lined up and tabs for the rest. Example: class Foo { \tint bar(int a, \t int b); };
- cheradenine01 14y agoYes, but you can't tell in your editor if you've got \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.
- deleted 14y ago[deleted]
- markokocic 14y agoThat's where one single rule helps: use only tabs for indentation and only spaces for alignment.
- dylan-m 14y agoIf you're trying to line things up with tabs, you're doing it wrong. Tabs are for indentation. Lining up columns is not indenting. (I'd also argue that trying to line stuff up like that is, nine times out of ten, doing it wrong: it inevitably leads to an if statement where the consequent is indented as much as the last line of conditions. If people are swearing by a style guide that says "always do this," and it's that, at least some of their code will end up being messy anyway).
- sp332 14y agoI have vim configured with 4-space tabs, but less(1) on my box uses 8-space tabs. I could reconfigure everything on my box to use 4-space tabs but it's easier to just have vim save tabs as spaces. 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.
- implicit 14y agoIf your team has more than one person in it, you have two choices for indentation: 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.
- countzeroasl 14y agoLess keystrokes = optmal laziness.
- lutusp 14y ago> Less keystrokes ... (groan) http://en.wikipedia.org/wiki/Fewer_vs._less http://en.wikipedia.org/wiki/Fewer_vs._less
- DanBC 14y agoDid you read the article you linked? > 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.
- lutusp 14y ago> Did you read the article you linked? 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.
- DanBC 14y agoHow is "less keystrokes" unclear?
- lutusp 14y agoIt argues that some keystrokes are smaller than others, because that's what "less" means -- it describes the size (not the number) of the things under discussion. 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.
- lutusp 14y agoAfter nearly 40 years' experience in programming, I offer that (as to computer source code) tabs should be outlawed. They are visually indistinguishable from spaces, they are handled differently in each editing environment, and they often result in difficult-to-detect bugs. 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.
- hboon 14y agoI see tab widths being configurable in editors as a major advantage over spaces. No more arguing over how many spaces, just use 1 tab and configure your own tab width, including for Python. In your experience, can you give an example of recurring bugs related to not being able to distinguish between tabs and spaces?
- lutusp 14y ago> 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.
- 14y ago
- petercooper 14y agoFor indentation, I want to type tabs and get spaces. 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..
- hboon 14y agoThanks. Updated the poll to clarify this.
- hboon 14y agoWhy do you want to end up with spaces? Consider the alternative: if you end up with a tab, what's the downside?
- drcyrusflame 14y agoOther coders you might be working with on the same project may be using a different editor with different tab-width settings which may lead to improper indentations making it hard to read the code.
- dragonwriter 14y agoWhat I'd generally prefer is tabs (keyed and stored) for block-structure indententation, and spaces for visual alignment of single logical expressions broken into multiple lines for readability (where you are aligning the following lines with some element of the preceding line.) 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.)
- lutusp 14y ago> if you end up with a tab, what's the downside? 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.
- nealabq 14y agoSpaces or my thumbs get bored. (Thumbs of the world unite!)
- nwmcsween 14y agoTabs with spaces to align, code indentation is a bunch of tabular data when you think of it.
- ollysb 14y agoIn languages that don't interpret indentation what is the advantage of using spaces? If you use tabs everyone can choose their preferred level of indentation. If you use spaces what's the advantage?
- deleted 14y ago[deleted]
- dylan-m 14y agoI use a text editor that was made this decade, so I don't really mind either way, as long as you pick _one_ for indenting with! And I don't mean "use the same in all of your files." That's fine, but it's common sense. (And indenting is not the same as lining up columns, so I don't mean that either). 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.
- mseepgood 14y agoTabs are the one true way. Their semantics mean 'indentation' and everyone can configure the editor according to his/her preferences.
- mikeratcliffe 14y agoI contribute to a lot of open source projects and used to be a fan of tabs but now I hate them. 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.
- steveax 14y agoI (slightly) prefer tabs because as others have noted, it allows different users to set their preferred indentation. I'm surprised no one has mentioned EditorConfig: http://editorconfig.org/ http://editorconfig.org/
- dennisgorelik 14y agoTabs look better in diffs.
- exelib 14y agotabs++, because: 1. I can configure my editor to show one tab as 2 spaces. 2. I use backspace to remove identation and most editors remove just one space and not four. Personally, I don't see any advantage for spaces and no any disvantage for tabs.
- joshka 14y agoTabs are to programming as God is to Religion: An invisible thing that makes no difference except to those that believe.