Closed Xaroth closed 8 years ago
I don't know about pep8 but I do like tabs in code for indentation. Spaces should be used in comments and for alignment.
Pep8 is Python's 'style guidelines'.. they are pretty ingrained and uniform: https://www.python.org/dev/peps/pep-0008/
Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.
Also, be aware that the indentation used by python is used as alignment, as well that mixing tabs with spaces generates TabError exceptions under python3, and is generally discouraged.
The main issue you will get with using tabs is that different editors show them differently, at which point the readability of your code takes a nosedive when people use a different editor than you (the author) have used, because suddenly code looks differently.
Example:
def a_very_long_function_name(with_very_long_arguments=None,
that_need_newlines_to_remain_readable=None)
In this case, you will need to use spaces to align the code, because if you use tabs, your 4-space-wide-tab editor will show it properly, but editors using 8-wide-tabs will show the second line to be misaligned.
Now with python's ability to define functions within functions, this becomes an impossible task as you would have to mix tabs and spaces in the same block (tabs for your normal indentation, and then spaces to align), which might not error in python2 (though the usage of the -tt argument is recommended and causes python2 to throw errors as well in these cases), but could generate potential issues which are extremely hard to spot.
In short, in python, using tabs is considered poor coding style, and yes, it does clash with other languages' defaults, however, spaces are much more compatible with tabs, than tabs are with spaces :)
Python has a chance to be a respectable language if it weren't for this!
heheh, agreed. I have never understood why this freedom of choosing among tabs and spaces if it is a critical part of the language and afterwards almighty pep8 comes and says to only use spaces.
On a side note I consider tabs superior as you can adjust their size to represent as many spaces as you want in the editor of your choosing, whereas with spaces you are fixed to the file's format. However Xaroth gave a pretty nice explanation I never read it before elsewhere.
Python focuses a lot on creating readable and manageable code, something not many other languages do.. part of this means that there has to be some set of rules in play, which luckily was decided on early-on in the creation of python... PEPs are a good example of this as well, as every change the community wants to bring forward has to be documented, weighed and evaluated, before it is accepted.
Besides, you can easily tell your editor to expand tabs to spaces (most respectable editors can do this), and for you (the developer) nothing changes, while your code will look exactly the same on everybody else's editor.
pep8 clearly suggests using spaces over tabs, as it breaks readability when editors use different settings for tab sizes.
Many clients use 4 spaces for each tab, while github shows them as 8, this instantly shows some discrepencies (like in the license file), example in src/tools/delstyles.py
This was introduced in during commit 429f77f