Alternate indent proposal for python 3000

Eric Wertman ewertman at gmail.com
Sun Apr 20 14:37:12 EDT 2008


On Apr 20, 1:29 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Sun, 20 Apr 2008 13:42:05 -0300, Matthew Woodcraft <matth... at chiark.greenend.org.uk> escribió:
>
> > An alternative scheme for describing the block structure could be
> > useful in other cases, though. For example, if you wanted to support
> > putting snippets of Python in configuration files, or spreadsheet
> > cells.
> > [...] If someone wrote a library for this and it proved popular, I expect it
> > would be considered for the standard library.
>
> There is "pindent.py" in the Tools/scripts directory:
>
> # ... When called as "pindent -r" it assumes its input is a
> # Python program with block-closing comments but with its indentation
> # messed up, and outputs a properly indented version.
>
> # A "block-closing comment" is a comment of the form '# end <keyword>'
> # where <keyword> is the keyword that opened the block ...
>
> def foobar(a, b):
>     if a == b:
>         a = a+1
>     elif a < b:
>         b = b-1
>         if b > a: a = a-1
>         # end if
>     else:
>         print 'oops!'
>     # end if
> # end def foobar
>
> --
> Gabriel Genellina

That's actually not a lot different than what you have to do now in a
web page.. It still seems overcomplicated though.  I'm not sure why
this is worse:

def foobar(a, b):
if a == b:
a = a+1;
elif a < b:
b = b-1;
if b > a:
a = a-1;
else:
print 'oops!';;

It's just ultimately whitespace insensitive.  Whether that's a good or
bad design is a debate that can be argued either way, but other
languages do it, and it's handy sometimes.  I agree that it makes it
much easier to produce illegible code.  Developing for a browser is
arguably annoying and hackish enough, without having to stick in
comments and such to enforce indenting.






More information about the Python-list mailing list