Also, because tab is a pointless character and an outdated hack.
The problem is, a "tab" does not advance by 8 spaces; it advances to the next column divisible by 8! Shockingly, most editor writers don't seem to realize this; this appears to be especially true in the Windows world (perhaps because they never used typewriters or ASCII terminals?)
The resultant code is only readable in an editor with the same settings; for a language like Python, the resultant code will, in fact, be semantically incorrect.
Some editors that are not broken (eg. emacs, vim), allow you to specify a desired indentation level, and then the editor constructs the correct combination of tabs and spaces (ideally just spaces, for Python) to indent the code to the correct depth.
This comes from someone who has to regularly recover code mangled by dozens of Windows "programmers" who edit code on so-called "Programmers" editors with alternate tab settings...
In older tabbed python code, I've seen numerous patches fail to run, because the patch had the wrong indentation scheme. Worse, were patches I've found that ran, but with subtle bugs, because the change in indentation modified the logic without runtime errors.
def x():<enter>
<tab>"Oh no I'm on the reply button!"<Shift+Tab><space><space><space><space>print "Much Better"
It's true there are tools, especially on the web, that eliminate whitespace and if you rely on those tools using python is going to be a problem. But generally it's pretty obvious whether that's going to be an issue. Tab problems tend to sneak up when you least expect it.
For example.
if foo:
[tab]bar #valid
if foo:
bar #valid
if foo:
if baz:
bar #valid
if foo:
if baz:
[tab]bar #invalid Your four spaces disappeared but it wasn't a DEDENT.
if foo:
if baz:
[tab]bar #This can be valid, I guess. Doesn't harm anyone.
Once you don't allow people to interchange tabs and spaces it's perfectly safe to set tab width to any amount.In other words, forcing everyone to use tab-characters for spacing would be a burden on the majority for the benefit of a tiny minority.
Well, unless you're just reading code.
A lot of python is convention based, and you can break all the rules you want and still have valid code, but no one else will want to use or maintain it.
if x:
----some_long_func_name(...,
---- blah...
Note that ---- is indentation and the spaces need to be spaces. If you use tabs for all of this, it will come out misaligned.You could say -- then why not use tabs for the indent part, and spaces for the alignment part? Because virtually no editors support doing this automatically (and doing this manually is not practical). The few editors that do support automating this, don't make it discoverable (let alone a default).
What you end up with is a horrible mixture of tabs and spaces, or if you use tabs only, then code that does not align right.
Using tabs simply does not work in practice. Spaces may have the (supposed) disadvantage of a fixed indentation size, but they really are the only way to make indented code work across different editors. And this is not an optional thing, therefore tabs should be banned, completely.
if x:
----some_long_func_name(...,
blah...)
----fn2(x)
else:
----fn3()
However, I do agree that using tabs in python quickly becomes an enormous headache."Using tabs simply does not work in practice."
Outside of the python community, "tabs for indentation, space for alignment" is quite common. Many people use it in practice, to say that it simply doesn't work is ignoring reality.
And then, when others edit the code -- the use some wrong mixture of tabs and spaces.
What I said is that it won't work in practice in a multi-editor environment. If everyone has a uniformly configured vim, it may work -- but no work environment I've seen ever had that.
EDIT: Can you name a single example project source I can look at that correctly uses tabs for indentation only?
I've never seen it work, it always deteriorates into a mess in my experience. Also, do you ever work with people who use Eclipse, Visual Studio, Notepad++, and various non-vim editors?