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…
But feeling that slight uncertainty again, I googled around a bit and came upon that wonderful page Indentation Using Tabs, where I could read:
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…





{ 5 } Comments
Why “discussing” about tabs or spaces? Peeking at old-fashioned programming-languages like Cobol or Fortran will give you an old-fashioned but consequential answer: use spaces – the only thing punchcards understand
Seriously, I would prefer tabs while coding, but would like them to become spaces for saving, ’cause tabs are what your editor wants them to be…
Lighthearted of difficult things you speak, young padawan!
I am convinced that tabs are the better abstraction for “one level of indentation”. They also save space (no pun intented) – so your punchcards would use tabs if they would at all bother about indentation…
In the last two weeks I worked with ‘real tabs’ and ‘spaces’ (convert-tab-to-spaces) and found several points:
So even though tabs are the better abstraction I’ll have to bend before the masses. That seesaw of converting spaces to tabs back and forth is just draining too much time and energy…
I recently went through a similar dilemma. I decided on tabs. Just trying to keep it simple.
very interesting, but I don’t agree with you
Idetrorce
@Idetrorce: Does this already qualify as an opinion?
Post a Comment