[Python-ideas] Pipe indentation

Daniel Watkins daniel at daniel-watkins.co.uk
Mon Dec 9 11:29:29 CET 2013


On Mon, Dec 09, 2013 at 09:11:09PM +1100, Chris Angelico wrote:
> On Mon, Dec 9, 2013 at 9:07 PM,  <musicdenotation at gmail.com> wrote:
> > 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.
> 
> Alternative suggestion: Tab indentation. Do exactly the same thing,
> but replace every pipe with a tab. Then you can set your editor to
> show indentation visibly (SciTE does this already).

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


More information about the Python-ideas mailing list