[Python-Dev] Re: anonymous blocks

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Apr 26 06:00:14 CEST 2005

Brett C. wrote:

> And before anyone decries the fact that this might confuse a newbie (which
> seems to happen with every advanced feature ever dreamed up), remember this
> will not be meant for a newbie but for someone who has experience in Python and
> iterators at the minimum, and hopefully with generators.

This is dangerously close to the "you don't need to know about
it if you're not going to use it" argument, which is widely
recognised as false. Newbies might not need to know all the
details of the implementation, but they will need to know
enough about the semantics of with-statements to understand
what they're doing when they come across them in other people's

Which leads me to another concern. How are we going to explain
the externally visible semantics of a with-statement in a way
that's easy to grok, without mentioning any details of the

You can explain a for-loop pretty well by saying something like
"It executes the body once for each item from the sequence",
without having to mention anything about iterators, generators,
next() methods, etc. etc. How the items are produced is completely
irrelevant to the concept of the for-loop.

But what is the equivalent level of description of the
with-statement going to say?

"It executes the body with... ???"

And a related question: What are we going to call the functions
designed for with-statements, and the objects they return?
Calling them generators and iterators (even though they are)
doesn't seem right, because they're being used for a purpose
very different from generating and iterating.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+

More information about the Python-Dev mailing list