3 ms·
If you use tabs everywhere, your code alignment will be all wrong: if x: ----some_long_func_name(..., ---- blah... Note that ---- is
by Peaker 15y ago
If you use tabs everywhere, your code alignment will be all wrong:
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.
- Goladus 15y agoTechnically that's incorrect. A parameter list has an implicit line continuation so the 4 spaces aren't necessary. 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.
- Peaker 15y agoMy point was not that the code becomes incorrect -- but that the point of indentation is to make code readable, and it is lost when using tabs because the only correct use of tabs for indentation is not well supported by editors in practice.
- burgerbrain 15y agoVim very easily allows me to use tabs for indentation and spaces for alignment... "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.
- Peaker 15y agoVim does not do this by default, you have to enable it explicitly. 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?