Tabs for indentation & Spaces for alignment in Python 3?

Ned Batchelder ned at nedbatchelder.com
Fri Dec 5 16:05:36 EST 2014


On 12/5/14 12:40 PM, Aahan Krish wrote:
> I have two general questions regarding Python that I couldn't find any
> good answers for. This is not the often-asked Tabs vs Spaces question,
> so kindly read it in whole.
>
> *Q1.* This is not to debate the decision, but I really wanted to know
> the reason why PEP 8 chose to go with spaces instead of tabs. I read
> that tabs were initially preferred over spaces (esp. Mr. Rossum)? What
> caused the decision that spaces are better?
>
> According to Core Python Programming (Book):
>
>     ...because tabs vary in the number of spaces depending on your
>     system, we recommend not using tabs if there is any hint of
>     cross-platform development.
>
>
> Isn't that a feature of tabs? (i.e. allowing the user to configure the
> size of a tab stop in his editor, which has no affect whatsoever on the
> tab character itself or how it displays in another user's editor.)

But you can't configure the width of tabs in all the places you look at 
code (printing, online repos, diff viewers, etc, etc).

Others have mentioned the awkward nature of over-indented continuation 
lines.

My feeling is that if you are working with others who feel strongly 
enough about differing indent widths that they need to use tabs so they 
can each have their own way, then you probably have bigger collaboration 
issues.

Use four spaces, and be done with it.  Agree with your team members on 
how your code will look, then innovate on the important things.

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list