Python indentation (3 spaces)

Peter J. Holzer hjp-python at hjp.at
Mon Oct 15 14:57:38 EDT 2018


On 2018-10-15 09:49:12 +1100, Cameron Simpson wrote:
> On 15Oct2018 00:33, Peter J. Holzer <hjp-python at hjp.at> wrote:
> > On 2018-10-15 09:06:11 +1100, Chris Angelico wrote:
> > > On Mon, Oct 15, 2018 at 8:56 AM Marko Rauhamaa <marko at pacujo.net> wrote:
> > > > Chris Angelico <rosuav at gmail.com>:
> > > > > Tabs for indentation have semantic meaning. Top-level has zero tabs.
> > > > > One indentation level is represented by one tab. Two indentation
> > > > > levels? Two tabs. It's about as perfect a representation as you could
> > > > > hope for.
> > > >
> > > > That *could* be the situation. However, it is trumped by an older
> > > > convention whereby the indentation levels go as follows:
> > > >
> > > >    0:
> > > >    1: SPC SPC
> > > >    2: SPC SPC SPC SPC
> > > >    3: SPC SPC SPC SPC SPC SPC
> > > >    4: TAB
> > > >    5: TAB SPC SPC
> > > >    6: TAB SPC SPC SPC SPC
> > > >    7: TAB SPC SPC SPC SPC SPC SPC
> > > >    8: TAB TAB
> > 
> > That's not using tabs for indentation, that's using tabs for compressing
> > spaces (somebody already mentioned that in this thread).
> > 
> > 
> > > I've literally NEVER come across this as a convention. Not a single
> > > file that I have ever worked with has used it. Where is this
> > > convention from?
> > 
> > It's something vi does by default, and apparently emacs as well.
> > In the 1970's saving space by replacing sequences of 8 spaces
> > with tabs seemed lika a good idea.
> > 
> > There are workarounds in vi(m), but I'm not sure if you can get rid of
> > that behaviour completely. I'm sure it is possible in emacs.
> 
> I'm a "just use spaces" guy.

So am I. As I wrote somewhere near the start of this thread, I find the
"1 tab per indentation level" theoretically appealing but unworkable in
practice. 


> I use the tab _key_ as a shortcut to do a bunch
> of spaces.
> 
> My vim setup has this:
> 
>  set expandtab
> 
> which turns them into spaces.

Yep, mine, too. But that doesn't help you if you want to use tabs
(the character ASCII 0x09, not the tab key) to signify an indentation
level in your files.

So it's sort of off-topic in this sub-thread.

My point was that with expandtab off, vim sometimes "optimizes"
sequences of spaces into tabs in places where it shouldn't, and that
it's hard (maybe impossible) to get vim leave tabs where they belong and
not introduce them where they don't belong. So it isn't the ideal editor
for the "1 tab per indentation level" style.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20181015/86df5dd0/attachment.sig>


More information about the Python-list mailing list