Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82021 > unrolled thread

Re: Tabs for indentation & Spaces for alignment in Python 3?

Started byCameron Simpson <cs@zip.com.au>
First post2014-12-06 07:37 +1100
Last post2014-12-06 10:47 +1100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Tabs for indentation & Spaces for alignment in Python 3? Cameron Simpson <cs@zip.com.au> - 2014-12-06 07:37 +1100
    Re: Tabs for indentation & Spaces for alignment in Python 3? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-06 09:29 +1100
      Re: Tabs for indentation & Spaces for alignment in Python 3? Cameron Simpson <cs@zip.com.au> - 2014-12-06 10:47 +1100

#82021 — Re: Tabs for indentation & Spaces for alignment in Python 3?

FromCameron Simpson <cs@zip.com.au>
Date2014-12-06 07:37 +1100
SubjectRe: Tabs for indentation & Spaces for alignment in Python 3?
Message-ID<mailman.16639.1417811883.18130.python-list@python.org>
On 05Dec2014 17:40, Aahan Krish <krish@aahan.me> wrote:
>*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?

Essentially because the space is always the same.

>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.)

Yes, but in practice it causes varying degrees of pain.

Ideally, the various pieces of code have differing indents and that would be 
specified entirely with tabs. In practice, (1) people mix them and (2) people 
make other formatting decisions based on the rendering width of tabs in 
whatever editor they're using at the time, particularly with multiline strings 
such as docstrings.

There are two common approaches to TABs: the purists who uses TABs entirely so 
that other users can align the code as they see fit, and the pragmatists who 
configure their editors to accept the TAB _keystroke_ and have it insert spaces 
according to their tab convention.

I'm in the latter category; I have spent too much time reading files indented 
with TABs by people using a different tabwidth to my own, and thus looking 
aweful on my screen. The original author didn't choose to make it awful, but 
their tabs rendered in my tab scheme look awful. And doubtless vice versa. The 
root cause of this is that when we, as humans, indent with tabs, we do it to 
achieve a certain visual effect; as though a certain number of spaces were in 
play.

So my editor is configured to accept the tab key for convenience of typing, but 
to insert spaces.

Cheers,
Cameron Simpson <cs@zip.com.au>

In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt.    - Blair P. Houghton

[toc] | [next] | [standalone]


#82025

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-12-06 09:29 +1100
Message-ID<548231be$0$12986$c3e8da3$5496439d@news.astraweb.com>
In reply to#82021
Cameron Simpson wrote:

> I have spent too much time reading files indented
> with TABs by people using a different tabwidth to my own, and thus looking
> aweful on my screen. The original author didn't choose to make it awful,
> but their tabs rendered in my tab scheme look awful. And doubtless vice
> versa. The root cause of this is that when we, as humans, indent with
> tabs, we do it to achieve a certain visual effect; as though a certain
> number of spaces were in play.

How is this different from people who achieve a certain visual effect by
indenting with actual spaces?

I've seen people indent with 8 spaces. I've seen people indent with 2
spaces. I've even seen people indent with a single space per level. I
haven't seen anyone indent with 17 spaces, but I suppose it's only a matter
of time...

I don't see how reading code indented with tabs configured for 8/4/2/1
spaces is *worse* than reading tab indented with 8/4/2/1 spaces.




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#82027

FromCameron Simpson <cs@zip.com.au>
Date2014-12-06 10:47 +1100
Message-ID<mailman.16643.1417825192.18130.python-list@python.org>
In reply to#82025
On 06Dec2014 09:29, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
>Cameron Simpson wrote:
>> I have spent too much time reading files indented
>> with TABs by people using a different tabwidth to my own, and thus looking
>> aweful on my screen. The original author didn't choose to make it awful,
>> but their tabs rendered in my tab scheme look awful. And doubtless vice
>> versa. The root cause of this is that when we, as humans, indent with
>> tabs, we do it to achieve a certain visual effect; as though a certain
>> number of spaces were in play.
>
>How is this different from people who achieve a certain visual effect by
>indenting with actual spaces?
>
>I've seen people indent with 8 spaces. I've seen people indent with 2
>spaces. I've even seen people indent with a single space per level. I
>haven't seen anyone indent with 17 spaces, but I suppose it's only a matter
>of time...
>
>I don't see how reading code indented with tabs configured for 8/4/2/1
>spaces is *worse* than reading tab indented with 8/4/2/1 spaces.

Because the author will have chosen a scheme not too insane. But when I pull up 
their indented-with-2-or-4-tab files in my tab==8 editor, it looks terrible.  
When I pull up their indented-with-spaces in whatever scheme, it looks as good 
or bad as their judgement, which even when tasteless is usually better than 
overwide tabs.

I would rather not have to readjust my editor's tab spacing every time I load 
up a file from someone-who-is-not-me. If they use spaces, I don't have to. If 
they use tabs and do not indent like I do, I have to to keep things readable.

Cheers,
Cameron Simpson <cs@zip.com.au>

They shouldn't get any new nuclear weapons until they've used the ones
they've got.    - Murff

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web