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


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

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

Started byMichael Torrie <torriem@gmail.com>
First post2014-12-05 20:04 -0700
Last post2014-12-07 03:46 +1100
Articles 7 — 3 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? Michael Torrie <torriem@gmail.com> - 2014-12-05 20:04 -0700
    Re: Tabs for indentation & Spaces for alignment in Python 3? Marko Rauhamaa <marko@pacujo.net> - 2014-12-06 10:40 +0200
      Re: Tabs for indentation & Spaces for alignment in Python 3? Michael Torrie <torriem@gmail.com> - 2014-12-06 09:41 -0700
        Re: Tabs for indentation & Spaces for alignment in Python 3? Marko Rauhamaa <marko@pacujo.net> - 2014-12-06 18:57 +0200
          Re: Tabs for indentation & Spaces for alignment in Python 3? Michael Torrie <torriem@gmail.com> - 2014-12-06 10:26 -0700
            Re: Tabs for indentation & Spaces for alignment in Python 3? Marko Rauhamaa <marko@pacujo.net> - 2014-12-06 22:04 +0200
      Re: Tabs for indentation & Spaces for alignment in Python 3? Chris Angelico <rosuav@gmail.com> - 2014-12-07 03:46 +1100

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

FromMichael Torrie <torriem@gmail.com>
Date2014-12-05 20:04 -0700
SubjectRe: Tabs for indentation & Spaces for alignment in Python 3?
Message-ID<mailman.16650.1417835105.18130.python-list@python.org>
On 12/05/2014 07:31 PM, Ned Batchelder wrote:
> This is a perfect example!  The code (with tabs as >--- and leading 
> spaces as .) is:
> 
>   >-------if (!list_empty(pending))
>   >------->-------ret = list_first_entry(pending, struct async_entry,
>   >------->------->------->-------.......domain_list)->cookie;
> 
> Now, display it in your editor with tabs set to four spaces:
> 
>   >---if (!list_empty(pending))
>   >--->---ret = list_first_entry(pending, struct async_entry,
>   >--->--->--->---.......domain_list)->cookie;

However, a conscientious programmer knows that tabs could be arbitrarily
sized, so he would never do that.  Instead he would do:

   >-------if (!list_empty(pending))
   >------->-------ret = list_first_entry(pending, struct async_entry,
   >------->-------.......................domain_list)->cookie;

Which under the heretical tab size of 4:
   >---if (!list_empty(pending))
   >--->---ret = list_first_entry(pending, struct async_entry,
   >--->---.......................domain_list)->cookie;

In fact a decent editor that is auto-indenting code would, at least in C
or C++ mode, do that automatically.

Maybe I misread, but I would think this is what the OP had in mind.
Of course maybe kernel programmers think differently.  Ahh well.



[toc] | [next] | [standalone]


#82037

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-12-06 10:40 +0200
Message-ID<87mw71maqu.fsf@elektro.pacujo.net>
In reply to#82034
Michael Torrie <torriem@gmail.com>:

> In fact a decent editor that is auto-indenting code would, at least in
> C or C++ mode, do that automatically.

A decent editor frees you from this dilemma entirely:

    (custom-set-variables
     '(indent-tabs-mode nil))

HT belongs together with VT, SOH and ETB.


Marko

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


#82039

FromMichael Torrie <torriem@gmail.com>
Date2014-12-06 09:41 -0700
Message-ID<mailman.16653.1417884132.18130.python-list@python.org>
In reply to#82037
On 12/06/2014 01:40 AM, Marko Rauhamaa wrote:
> Michael Torrie <torriem@gmail.com>:
> 
>> In fact a decent editor that is auto-indenting code would, at least in
>> C or C++ mode, do that automatically.
> 
> A decent editor frees you from this dilemma entirely:
> 
>     (custom-set-variables
>      '(indent-tabs-mode nil))

What dilemma?  Do you mean you can avoid the drama of tabs by going all
spaces?  Of course in Python this is the recommended course.

But that's typically not what I, or most people, use in C or C++.  And
one of the OP's points is that by using tabs for indent, and spaces for
alignment, you can have the best of both worlds.  Programmers can set
their tab size to anything they want, and it still looks good (except of
Linux kernel source code, which only will ever look right at tabs
equivalent to 8 spaces).  He wanted to know if he could still do that in
Python3, and the answer is "yes" although we recommend highly just
sticking to pep8 4 space characters per indent and no tabs whatsoever.

Of course any validly-formatted Python code (or C code) can be made to
look right and work right by running autopep8[1] on it.  Just like
"indent" can make your C code fit whatever style guide you need.

[1] https://pypi.python.org/pypi/autopep8/

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


#82041

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-12-06 18:57 +0200
Message-ID<87d27wlnr4.fsf@elektro.pacujo.net>
In reply to#82039
Michael Torrie <torriem@gmail.com>:

> What dilemma?  Do you mean you can avoid the drama of tabs by going all
> spaces?  Of course in Python this is the recommended course.
>
> But that's typically not what I, or most people, use in C or C++.

"Most people"? Hm. I don't know most people.

Anyway. Who cares about "most people"?

> And one of the OP's points is that by using tabs for indent, and
> spaces for alignment, you can have the best of both worlds.

I certainly doesn't sound that way.

> Programmers can set their tab size to anything they want, and it still
> looks good

That's anything but true. I see zigzaggy diffs all the time.


Marko

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


#82042

FromMichael Torrie <torriem@gmail.com>
Date2014-12-06 10:26 -0700
Message-ID<mailman.16655.1417886776.18130.python-list@python.org>
In reply to#82041
On 12/06/2014 09:57 AM, Marko Rauhamaa wrote:
>> And one of the OP's points is that by using tabs for indent, and
>> spaces for alignment, you can have the best of both worlds.
> 
> I certainly doesn't sound that way.

Why is that?

> 
>> Programmers can set their tab size to anything they want, and it still
>> looks good
> 
> That's anything but true. I see zigzaggy diffs all the time.

You're not reading what I'm writing, at least understanding it.  The
idea behind using tabs for indent and spaces for alignment are clear enough:
>------->-------blah (one,
>------->-------......two

So obviously your zigzaggy diffs are showing that the person who wrote
the code is *not* using tabs for indent and spaces for alignment.  Must
just be using tabs.  Since tabs and spaces are not visibly
distinguished, it's not readily apparent when one is properly using tabs
and spaces together, and not apparent that your editor is doing it
properly, so in Python most people recommend never mixing tabs and
spaces, although you *can* do that in the way I've described if you
really want to.

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


#82045

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-12-06 22:04 +0200
Message-ID<878uiklf3g.fsf@elektro.pacujo.net>
In reply to#82042
Michael Torrie <torriem@gmail.com>:

> So obviously your zigzaggy diffs are showing that the person who wrote
> the code is *not* using tabs for indent and spaces for alignment.

Source code lives easily for ten years or longer. It is touched by
numerous people in different groups or even companies under different
stylistic preferences. In fact, people rarely have the luxury or
inclination to think in terms of style.

> Since tabs and spaces are not visibly distinguished, it's not readily
> apparent when one is properly using tabs and spaces together,

Your "properly" is different from my "properly," I bet.


Marko

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


#82040

FromChris Angelico <rosuav@gmail.com>
Date2014-12-07 03:46 +1100
Message-ID<mailman.16654.1417884382.18130.python-list@python.org>
In reply to#82037
On Sun, Dec 7, 2014 at 3:41 AM, Michael Torrie <torriem@gmail.com> wrote:
> What dilemma?  Do you mean you can avoid the drama of tabs by going all
> spaces?  Of course in Python this is the recommended course.

Actually it's only one of several recommended courses, but otherwise yes. :)

ChrisA

[toc] | [prev] | [standalone]


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


csiph-web