For a while I’ve been pondering whether I should use spaces or tabs to indent python-code.
On WhitespaceInPython I’ve collected some pros and cons and finally decided that tabs are the way to go for me. This decision was based, amongst other arguments, on this comment to A Brief Defense of Significant Whitespace:
Indentation consistency becomes easy if everyone agrees to use tabs. Then, each user, in their editor of choice, needs to decide what their tabstop should be.
If you don’t like huge indentations, set your tabstop to 4, or dare to even try 2.
If you like lots of whitespace, set the tabstop to 8. If your editor can’t do this, get yourself a good editor.
I never really understood why the BDFL feels so strongly about using spaces for indentation:
If it uses two-space indents, it’s corporate code; if it uses four-space indents, it’s open source. (If it uses tabs, I didn’t write it! [source]
On Friday WhitespaceInPython was edited by someone calling himself ‘thyself’, adding:
Guns don’t kill people, bullets kill people. And tabs don’t mess up code, editing does. As long as you don’t need to ever change the code, or transfer it, or refer to column numbers, or use different editors, or different environments, or post it on message boards, etc., no problem. In real life though, use consistent spaces to obtain consistent results.
Though bullets are another story (see PowerPoint), and I almost never refer to column numbers (;-)), I see the weight of the points made. Time to switch back to spaces?
Frankly, I currently feel quite comfortable with tabs and use them all over the place. I haven’t run into trouble using them but may switch back to spaces if I finally do…
Like the Newline, Tabs also have special meaning. Using Spaces to get to the next level of indention is no more acceptable than using Spaces to advance the cursor to the beginning of the next visual line. Tabs and Newlines contain metainformation about the code that using an arbitrary amount of spaces to get the same visual effect does not have.
I think I’ll stick with tabs. They just feel more sensible…