[Python-Dev] Re: PEP 340 - possible new name for block-statement

Nicolas Fleury nidoizo at yahoo.com
Fri Apr 29 05:21:12 CEST 2005


Guido van Rossum wrote:
> A variation on this with somewhat different semantics swaps the keywords:
> 
>     in EXPR for VAR:
>         BLOCK
> 
> If you don't need the variable, you can leave the "for VAR" part out:
> 
>     in EXPR:
>         BLOCK
> 
> Too cute? :-)
> 

I don't think it reads well.  I would prefer something that would be 
understandable for a newbie's eyes, even if it fits more with common 
usage than with the real semantics behind it.  For example a Boost-like 
keyword like:

scoped EXPR as VAR:
     BLOCK

scoped EXPR:
     BLOCK

We may argue that it doesn't mean a lot, but at least if a newbie sees 
the following code, he would easily guess what it does:

scoped synchronized(mutex):
     scoped opening(filename) as file:
         ...

When compared with:

in synchronized(mutex):
     in opening(filename) for file:
         ...

As a C++ programmer, I still dream I could also do:

scoped synchronized(mutex)
scoped opening(filename) as file
...

which would define a block until the end of the current block...

Regards,
Nicolas



More information about the Python-Dev mailing list