News for hackers. Stuff that matters.
Re:Poll: Spaces or tabs? by lutusp on Saturday February 02, 2013 @10:50AM (#5156218)
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.

Re:Poll: Spaces or tabs? by hboon on Saturday February 02, 2013 @11:02AM (#5156263)
I 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?

Re:Poll: Spaces or tabs? by lutusp on Saturday February 02, 2013 @11:15AM (#5156324)
> 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.

Re:Poll: Spaces or tabs? by burntsushi on Saturday February 02, 2013 @11:25AM (#5156363)
> 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?

Re:Poll: Spaces or tabs? by lutusp on Saturday February 02, 2013 @04:51PM (#5157494)
> 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.

Re:Poll: Spaces or tabs? by burntsushi on Sunday February 03, 2013 @04:17PM (#5161190)
> 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.

Re:Poll: Spaces or tabs? by hboon on Saturday February 02, 2013 @11:34AM (#5156395)
> 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?

Re:Poll: Spaces or tabs? by jabbernotty on Saturday February 02, 2013 @12:37PM (#5156633)
The problem is that different people use different editors that have different settings. One person uses four spaces, another used 8 spaces, and a third uses tabs. Suddenly, your python code doesn't work well anymore, commits/diffs become very confusing and web services that have source viewers produce messy views.
Re:Poll: Spaces or tabs? by lutusp on Saturday February 02, 2013 @04:42PM (#5157456)
> 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.

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.

Re:Poll: Spaces or tabs? by mseepgood on Saturday February 02, 2013 @12:09PM (#5156539)
> 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.

The question begins with "If it didn't matter syntactically with the programming language".

Re:Poll: Spaces or tabs? by lutusp on Saturday February 02, 2013 @04:43PM (#5157460)
> 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.

Re:Poll: Spaces or tabs? by wglb on Saturday February 02, 2013 @11:54AM (#5156474)
Makefiles.
Re:Poll: Spaces or tabs? by wglb on Saturday February 02, 2013 @11:53AM (#5156472)
You 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.

Re:Poll: Spaces or tabs? by mseepgood on Saturday February 02, 2013 @12:00PM (#5156508)
Ken Thompson and the Go team explain why they prefer tabs: http://www.youtube.com/watch?v=sln-gJaURzk&t=28m55s
Re:Poll: Spaces or tabs? by wglb on Saturday February 02, 2013 @12:09PM (#5156536)
Thanks.

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.