3 ms·
After nearly 40 years' experience in programming, I offer that (as to computer source code) tabs should be outlawed. They are visually indistinguishable from sp
by lutusp 14y ago
After 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.
- burntsushi 14y ago> 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. 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?
- lutusp 14y ago> 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.
- burntsushi 14y ago> Translation: "If we eliminate any chance that a tab will be misinterpreted, can you think of a case where a tab might be misinterpreted?" 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.
- hboon 14y ago> 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. 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?
- wglb 14y agoMakefiles.
- wglb 14y agoYou know, I was with this right up till golang which uses tabs. So there is one excuse. So I suggest doing spaces except when writing GO, then use tabs.
- mseepgood 14y agoKen Thompson and the Go team explain why they prefer tabs: http://www.youtube.com/watch?v=sln-gJaURzk&t=28m55s http://www.youtube.com/watch?v=sln-gJaURzk&t=28m55s
- wglb 14y agoThanks. 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.