why no "do : until"?
Peter Hansen
peter at engcorp.com
Thu Jan 4 01:05:04 EST 2001
Alex Martelli wrote:
>
> "Peter Hansen" <peter at engcorp.com> wrote:
> [snip]
> > I can see your point (remarkable, given this thread, isn't it? :-). I
> > guess I consider the "block" to be everything except the code that allows
> > entry into the block.
>
> So what about:
> try:
> <suite1>
> except something:
> <suite2>
> and so on? Would you like it better if the 'except' was indented? It's
> NOT, after all, 'code that allows entry' in the "block" (overall try/except
> statement).
I _do_ consider it to be 'code that allows entry' into the block. After
all, there are _two_ blocks here, nested inside a single outer block:
try:
block1
except:
block2
To me, a block is a set of statements which are indivisibly executed
when unexceptional operation occurs (within the block). That is,
assuming no exceptions occur, all statements within block1 execute.
After a possible exception occurs, all statements in block2 execute.
(Don't bother taking that definition too literally. I understand
the possibly of a return in the middle of the code, etc. It's the
spirit of this definition I want to communicate, not the letter. :)
These two blocks are effectively just 'sub-blocks' of whatever block
of code contains the whole 'try/except' statement, which may or
may not have preceeding and following statements.
So no, I most definitely would have trouble if the 'except' statement
were to be indented, since it is _not_ part of the <suite1> block
in the 'try' portion of the code.
The graphical examination of the three brace/indentation styles in
Code Complete by McCarthy is, in my opinion, an excellent way of
comparing the alternatives. I can't imagine anyone feeling
wholly comfortable with the traditional K&R style after reading
that section. I was extremely happy to discover, in my first
moments looking at Python code, that the indentation-based
syntax of Python exactly maps to the style I've used for so long
and which McCarthy argues is superior.
More information about the Python-list
mailing list