Who are the "spacists"?

Chris Angelico rosuav at gmail.com
Mon Mar 20 11:32:55 EDT 2017


On Tue, Mar 21, 2017 at 2:19 AM, BartC <bc at freeuk.com> wrote:
> But tabs are also used after statements, before comments for example, or to
> line up elements in tables. Then it doesn't work, because tabs may represent
> 1 to N spaces:
>
> Using N=4, with 1 tab before each number:
>
>     (one,   1),         #comment 1
>     (two,   2),         #comment 2
>     (three, 3),         #comment 3
>
> Displayed using N=3:
>
>    (one, 1),         #comment 1
>    (two, 2),         #comment 2
>    (three,  3),         #comment 3
>
> Displayed using N=6:
>
>        (one, 1),               #comment 1
>        (two, 2),               #comment 2
>        (three,     3),               #comment 3
>
> Even tabs at the start of a line are sometimes using to line things up with
> a previous line; here with N=4, and 5 tabs before B and C:
>
>  longfunctionname (  A,  #comment 1
>                      B,  #comment 2
>                      C)  #comment 3
>
> With N=2:
>
> longfunctionname (  A,  #comment 1
>           B,  #comment 2
>           C)  #comment 3
>
> With N=8:
>
> longfunctionname (  A,  #comment 1
>                                         B,      #comment 2
>                                         C)      #comment 3

My points here are the same as for the other examples:

1) Preferably, don't do it at all.
2) If you absolutely have to do it, then by definition you're counting
character slots, so use spaces, not tabs.

Note that PEP 8 specifically forbids one of these kinds of usages:

"""
More than one space around an assignment (or other) operator to align
it with another.

Yes:

x = 1
y = 2
long_variable = 3

No:

x             = 1
y             = 2
long_variable = 3
"""

The reasoning behind this also applies to most of the other forms:
you're fiddling with formatting in ways that have to be forever
fiddled with as you make edits.

Here's a suggestion: Use a single tab after a statement and before the
hash. Exactly one tab. Then configure your editor to right-align that.
If someone else's editor doesn't right-align, no big deal, and you'll
get some measure of alignment anyway (eg if tabs are every eight
spaces, it rounds the alignment off to the next eight-mark); it won't
hurt anything, as those of us who don't care about the alignment won't
be bothered anyway.

ChrisA



More information about the Python-list mailing list