5 ms·
The standard indentation is 4 spaces, and people often have their tabwidth set to 4 spaces. Sometimes tabbed code (often older code, before spaces were really s
by ominous_prime 15y ago
The standard indentation is 4 spaces, and people often have their tabwidth set to 4 spaces. Sometimes tabbed code (often older code, before spaces were really standard), end up with mixed tabs and spaces. The logic of the code then reads completely differently depending on your editor settings.
- burgerbrain 15y agoI'm not advocating people mix tabs and spaces, I'm advocating that people always use tabs so that others can display it as they wish.
- Goladus 15y agoI think most people would rather use spaces for their own sanity. Most people would prefer not to bother adjusting tabwidths, ever. So the capability to adjust the display of code to individual's liking would be largely unappreciated. 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.
- jamesgeck0 15y agoThe majority has to change their editor's settings to insert four spaces instead of a tabulation, anyway. Well, unless you're just reading code.
- Goladus 15y agoI suspect most python developers get the "insert four spaces per tab" for free with whatever IDE they use.
- ominous_prime 15y agoThere's no drawback if you're working alone. The rest of the community however, decided that spaces are the standard. Yes it's somewhat arbitrary (golang picked tabs for instance), but if you don't want to conform to the community coding standards, it only brings hardship upon yourself. 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.
- Peaker 15y agoIf 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.
- 15y ago