PEP8 and 4 spaces
steve+comp.lang.python at pearwood.info
Fri Jul 4 03:21:36 CEST 2014
On Thu, 03 Jul 2014 21:07:28 +0300, Paul Sokolovsky wrote:
> On Fri, 4 Jul 2014 03:38:27 +1000
> Chris Angelico <rosuav at gmail.com> wrote:
>> On Fri, Jul 4, 2014 at 3:31 AM, Tobiah <tshepard at rcsreg.com> wrote:
>> > Coworker takes PEP8 as gospel and uses 4 spaces to indent. I prefer
>> > tabs. Boss want's us to unify.
>> 1) PEP 8 is meant to be guidelines, *not* a set of hard-and-fast rules.
>> 2) Tabs let different people display the indents at different widths.
> That's exactly the problem with tabs - whatever you think your code
> looks like with tabs, other people will see quite different picture.
Why do you consider this a problem?
The only rational reason I can think of is that you are concerned about
line widths. If I write code with tabs set to two spaces, indent five
times, and then write 50 characters of code, I'll see a total line width
of 60 columns. Somebody who views tabs as four spaces will see a width of
70, and someone else who views them as eight spaces will see a width of
90 columns. So I can see that's somewhat of a problem, but not a huge one.
> Also, most people are not interested in doing mumbo-jumbo with tabs
> settings, and have them set to standard 8-char tabs. So, any python code
> which uses only tabs for indentation automatically violates 4-space
"Mumbo-jumbo"? In any decent editor, it's a single setting. In kwrite I
go Settings > Configure Editor, click the Editing icon, and there's a
"Tab width" field right there. Hardly mumbo-jumbo.
In any case, the 4-space convention is just a convention. If you're
willing to go against PEP 8 and use tabs, going against PEP 8 and using 8-
column tab settings shouldn't worry you.
> (and mixing tabs and spaces is nowadays prohibited in Python).
Yes, that's because the algorithm used by the parser to determine the
indentation level may not give the same answer as a human reader, in the
presence of mixed tabs and spaces. In any case, in the entire history of
the space/tab argument, I'm not aware of a single person who recommended
mixed space/tabs for indents. There are two standard solutions for the
problem of indenting code, not three: use spaces, or use tabs, but not
"arbitrarily pick one or the other each time you indent".
> Summing up: if you care about other human beings, use spaces. If you
> don't care about other human beings, you may use tabs, but other human
> beings surely will take how you treat them into account ;-).
Ha ha, that's funny, I would have said the opposite: if you care about
keeping tools that expect spaces happy, use spaces, if you care about
allowing people to configure the look of your code, or poor unfortunates
who aren't using a programmer's editor, use tabs.
More information about the Python-list