PEP #99484663

bboman at research.panasonic.com bboman at research.panasonic.com
Thu Nov 14 13:31:01 EST 2002


Russell Nelson <nelson at crynwr.com> wrote in message news:<m2isz6ue4f.fsf at desk.crynwr.com>...
> Suggested PEP:
> 
> Treat { and } when encountered at the end of a statement like this:
> 
> When you see a {, generate an error if the next statement is not
> indented more than the previous statement.  When you see }, generate
> an error if the next statement is not indented less than the previous
> statement.
> 
> In this manner, people who are unable to wean themselves from silly
> syntactic block structure tokens will be happy with Python, rather
> than continually whinging about how horrible it is that indentation is
> meaningful to the program.

I also would like to see *OPTIONAL* block delimiters, but I wouldn't
do it
with {}.  It turns out that there are several keywords in Python like
"return"
"raise", "break", "continue" and "pass" that pretty much have to end a
block.  Technically "pass" doesn't have to end a block but there is no
point in putting "pass" anywhere except at a block end.

All you need to do to implement block delimiters is to have a option
to check that each block ends with one of these statements and that
these statements do not appear anywhere except at the end of a block. 
Now you have full block delimiters and complete compatibility with
normal python code!

It turns out that the python mode for emacs assumes that these keyword
end blocks and if you code this way emacs can completely recover the
indentation from the keywords.

I could go into a long explanation as to why block delimiters are
useful but I will just say that when you cut and paste a block of code
from one nested block loop into another block at a different
indentation level it is much nicer and much less error prone to just
tell emacs to re-indent the entire function than to manually adjust
each line.



More information about the Python-list mailing list