
if condition: | do_this | if cond2: | |do_that else: | do_this_instead This has the advantage of you always knowing which nesting level you are.

On Mon, Dec 09, 2013 at 09:11:09PM +1100, Chris Angelico wrote:
Alternative suggestion: indent with 4 spaces. Do exactly the same thing, but replace every pipe with 4 spaces. Then you can set your eyes to see the visible indentation. ;) More seriously, if you are at the point where you're getting confused by levels of indentation, you're probably either (a) nesting too much, or (b) including too much in indented blocks. Either of these can be solved by splitting your code up in to more smaller functions/methods (which, if you name them well, will have the side-effect of making your code clearer anyway!). Cheers, Dan

2013/12/9 Chris Angelico <rosuav@gmail.com>
that’s also my favourite way to do it. some editors can show tabs as an slim unobtrusive slim line and leading/trailing spaces as middle dots (·) that way you can not only instantly see all misplaced whitespace characters, but also indentation levels. (one tab per indentation level is pretty much as semantically unambiguous as it can get)

On 12/09/2013 04:07 AM, musicdenotation@gmail.com wrote:
Here's a link to a screen shot that shows Sublime Text's nesting level lines: http://imgur.com/yRGNCKu ...a lot of editors do this, tab or space. p.s. - it's not my code in the screen shot, its from the powerline module for vim (just grabbed the closest thing with nesting). -- - Christopher Welborn <cjwelborn@live.com> http://welbornprod.com

Christopher Welborn writes:
Here's a link to a screen shot that shows Sublime Text's nesting level lines:
...a lot of editors do this, tab or space.
But do they get it Pythonically correct? Ie, in counting indentation, 1 TAB = 1 SPC, regardless of what it looks like on screen.

On Mon, Dec 9, 2013 at 9:48 PM, Chris Angelico <rosuav@gmail.com> wrote:
The default Python 2 rule is actually that 1 TAB == 8 SPC.
SciTE gets it Python3ically correct: tab != space regardless of number.
Right. And in Python 2 you can get the same effect with python -tt. -- --Guido van Rossum (python.org/~guido)

Chris Angelico writes:
Oops, that's TAB = SPC*8 in Python 2.
SciTE gets it Python3ically correct: tab != space regardless of number.
But what does that mean? How does SciTE distinguish between "SPC TAB" at the beginning of line and just "TAB"? Where does it place guidelines given def f(x): SPC if x: SPC SPC print("gotcha") SPC else: SPC TAB print("gotcha again") which is acceptable to Python 3.3? I suppose the right answer, as usual, is "don't use both spaces and tabs for indentation in the same program", but I guess then it really doesn't matter how the editor handles tabs and spaces. Oh, BTW, I'm definitely -1 on "pipe indentation" in the source program, since editors can clearly do it if you want it (I don't) whether it's present in the source, or not.

On Tue, Dec 10, 2013 at 6:02 PM, Stephen J. Turnbull <stephen@xemacs.org> wrote:
Hmm, actually I have no idea, so I just checked. Seems I was slightly wrong in my description; the guides seem to be at fixed column positions (configurable, but not dynamic). The differentiation between tab and space is only for its signalling highlight - if you mismatch indentation in any way, the wrong one is highlighted with a very visible marker. And that highlight correctly accepts your above example, though it's a little finicky to type (putting a space, then a tab, on an otherwise-blank line deletes the space, but one can be explicitly inserted after the tab's already there). The upshot is that you get instant feedback if you ever get tabs/spaces wrong, and you get nice guides if you always indent consistently, and in between is shooting yourself in the foot anyway. ChrisA

On Tue, Dec 10, 2013 at 12:35 AM, Stephen J. Turnbull <stephen@xemacs.org> wrote:
Probably the first time significant thought was put into this was when I designed the -t/-tt option for Python 2. I don't recall when that was but it was in a very early Python 2 release. Everything else seems just derivative to me -- either the same solution, or buggy. :-) -- --Guido van Rossum (python.org/~guido)

Just to throw another editor's hat in the ring, the best way to achieve this in vim is with the indent-guides plugin https://github.com/nathanaelkane/vim-indent-guides however in stock vim, you can use 'listchars' to render a tab as a pipe followed by spaces. -Matt Boehm On Tue, Dec 10, 2013 at 1:32 PM, Ryan Gonzalez <rymg19@gmail.com> wrote:

On Tue, 10 Dec 2013 14:21:07 +0900 "Stephen J. Turnbull" <stephen@xemacs.org> wrote:
Generally they're purely graphical, i.e. they don't care about the *logical nesting* of your code, only about how many spaces are drawn on screen. (no, I don't know what it does with a non-monospaced font) Regards Antoine.

A space is always the same width, and tabs are normally rendered as multiple spaces in code editors, so it works just fine. Word wrap is where things get fun... (though I've only had one person complain that my Visual Studio extension doesn't handle it properly... who wraps code?) Top posted from my Windows Phone ________________________________ From: Antoine Pitrou<mailto:solipsis@pitrou.net> Sent: 12/11/2013 0:36 To: python-ideas@python.org<mailto:python-ideas@python.org> Subject: Re: [Python-ideas] Pipe indentation On Tue, 10 Dec 2013 14:21:07 +0900 "Stephen J. Turnbull" <stephen@xemacs.org> wrote:
Generally they're purely graphical, i.e. they don't care about the *logical nesting* of your code, only about how many spaces are drawn on screen. (no, I don't know what it does with a non-monospaced font) Regards Antoine. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

On Dec 11, 2013, at 15:45, Steve Dower <Steve.Dower@microsoft.com> wrote:
A space is always the same width, and tabs are normally rendered as multiple spaces in code editors, so it works just fine. Word wrap is where things get fun... (though I've only had one person complain that my Visual Studio extension doesn't handle it properly... who wraps code?)
You mean viewing soft-wrapped if it goes beyond the window width? I do that (when I can't just reject or edit the code to fit properly in the first place). Much better than horizontally scrolling, especially in a terminal session. It's ugly no matter what you do, but at least you can see it.

On 12/09/2013 11:21 PM, Stephen J. Turnbull wrote:
Whatever you set the tab-spacing to is what it shows up as. I set mine to 4 so the pic shows 4. If you set it to 1 or 2 you will see a lot of vertical lines. -- - Christopher Welborn <cjwelborn@live.com> http://welbornprod.com

On Mon, Dec 09, 2013 at 09:11:09PM +1100, Chris Angelico wrote:
Alternative suggestion: indent with 4 spaces. Do exactly the same thing, but replace every pipe with 4 spaces. Then you can set your eyes to see the visible indentation. ;) More seriously, if you are at the point where you're getting confused by levels of indentation, you're probably either (a) nesting too much, or (b) including too much in indented blocks. Either of these can be solved by splitting your code up in to more smaller functions/methods (which, if you name them well, will have the side-effect of making your code clearer anyway!). Cheers, Dan

2013/12/9 Chris Angelico <rosuav@gmail.com>
that’s also my favourite way to do it. some editors can show tabs as an slim unobtrusive slim line and leading/trailing spaces as middle dots (·) that way you can not only instantly see all misplaced whitespace characters, but also indentation levels. (one tab per indentation level is pretty much as semantically unambiguous as it can get)

On 12/09/2013 04:07 AM, musicdenotation@gmail.com wrote:
Here's a link to a screen shot that shows Sublime Text's nesting level lines: http://imgur.com/yRGNCKu ...a lot of editors do this, tab or space. p.s. - it's not my code in the screen shot, its from the powerline module for vim (just grabbed the closest thing with nesting). -- - Christopher Welborn <cjwelborn@live.com> http://welbornprod.com

Christopher Welborn writes:
Here's a link to a screen shot that shows Sublime Text's nesting level lines:
...a lot of editors do this, tab or space.
But do they get it Pythonically correct? Ie, in counting indentation, 1 TAB = 1 SPC, regardless of what it looks like on screen.

On Mon, Dec 9, 2013 at 9:48 PM, Chris Angelico <rosuav@gmail.com> wrote:
The default Python 2 rule is actually that 1 TAB == 8 SPC.
SciTE gets it Python3ically correct: tab != space regardless of number.
Right. And in Python 2 you can get the same effect with python -tt. -- --Guido van Rossum (python.org/~guido)

Chris Angelico writes:
Oops, that's TAB = SPC*8 in Python 2.
SciTE gets it Python3ically correct: tab != space regardless of number.
But what does that mean? How does SciTE distinguish between "SPC TAB" at the beginning of line and just "TAB"? Where does it place guidelines given def f(x): SPC if x: SPC SPC print("gotcha") SPC else: SPC TAB print("gotcha again") which is acceptable to Python 3.3? I suppose the right answer, as usual, is "don't use both spaces and tabs for indentation in the same program", but I guess then it really doesn't matter how the editor handles tabs and spaces. Oh, BTW, I'm definitely -1 on "pipe indentation" in the source program, since editors can clearly do it if you want it (I don't) whether it's present in the source, or not.

On Tue, Dec 10, 2013 at 6:02 PM, Stephen J. Turnbull <stephen@xemacs.org> wrote:
Hmm, actually I have no idea, so I just checked. Seems I was slightly wrong in my description; the guides seem to be at fixed column positions (configurable, but not dynamic). The differentiation between tab and space is only for its signalling highlight - if you mismatch indentation in any way, the wrong one is highlighted with a very visible marker. And that highlight correctly accepts your above example, though it's a little finicky to type (putting a space, then a tab, on an otherwise-blank line deletes the space, but one can be explicitly inserted after the tab's already there). The upshot is that you get instant feedback if you ever get tabs/spaces wrong, and you get nice guides if you always indent consistently, and in between is shooting yourself in the foot anyway. ChrisA

On Tue, Dec 10, 2013 at 12:35 AM, Stephen J. Turnbull <stephen@xemacs.org> wrote:
Probably the first time significant thought was put into this was when I designed the -t/-tt option for Python 2. I don't recall when that was but it was in a very early Python 2 release. Everything else seems just derivative to me -- either the same solution, or buggy. :-) -- --Guido van Rossum (python.org/~guido)

Just to throw another editor's hat in the ring, the best way to achieve this in vim is with the indent-guides plugin https://github.com/nathanaelkane/vim-indent-guides however in stock vim, you can use 'listchars' to render a tab as a pipe followed by spaces. -Matt Boehm On Tue, Dec 10, 2013 at 1:32 PM, Ryan Gonzalez <rymg19@gmail.com> wrote:

On Tue, 10 Dec 2013 14:21:07 +0900 "Stephen J. Turnbull" <stephen@xemacs.org> wrote:
Generally they're purely graphical, i.e. they don't care about the *logical nesting* of your code, only about how many spaces are drawn on screen. (no, I don't know what it does with a non-monospaced font) Regards Antoine.

A space is always the same width, and tabs are normally rendered as multiple spaces in code editors, so it works just fine. Word wrap is where things get fun... (though I've only had one person complain that my Visual Studio extension doesn't handle it properly... who wraps code?) Top posted from my Windows Phone ________________________________ From: Antoine Pitrou<mailto:solipsis@pitrou.net> Sent: 12/11/2013 0:36 To: python-ideas@python.org<mailto:python-ideas@python.org> Subject: Re: [Python-ideas] Pipe indentation On Tue, 10 Dec 2013 14:21:07 +0900 "Stephen J. Turnbull" <stephen@xemacs.org> wrote:
Generally they're purely graphical, i.e. they don't care about the *logical nesting* of your code, only about how many spaces are drawn on screen. (no, I don't know what it does with a non-monospaced font) Regards Antoine. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

On Dec 11, 2013, at 15:45, Steve Dower <Steve.Dower@microsoft.com> wrote:
A space is always the same width, and tabs are normally rendered as multiple spaces in code editors, so it works just fine. Word wrap is where things get fun... (though I've only had one person complain that my Visual Studio extension doesn't handle it properly... who wraps code?)
You mean viewing soft-wrapped if it goes beyond the window width? I do that (when I can't just reject or edit the code to fit properly in the first place). Much better than horizontally scrolling, especially in a terminal session. It's ugly no matter what you do, but at least you can see it.

On 12/09/2013 11:21 PM, Stephen J. Turnbull wrote:
Whatever you set the tab-spacing to is what it shows up as. I set mine to 4 so the pic shows 4. If you set it to 1 or 2 you will see a lot of vertical lines. -- - Christopher Welborn <cjwelborn@live.com> http://welbornprod.com
participants (15)
-
Andrew Barnert
-
Antoine Pitrou
-
Chris Angelico
-
Christopher Welborn
-
Daniel Watkins
-
Guido van Rossum
-
Mark Lawrence
-
Matthew Boehm
-
musicdenotation@gmail.com
-
Philipp A.
-
Ryan Gonzalez
-
Skip Montanaro
-
spir
-
Stephen J. Turnbull
-
Steve Dower