PEP 255: Simple Generators
Tim Peters
tim.one at home.com
Tue Jun 19 20:06:04 EDT 2001
[Carsten Geckeler]
> But when I'm browsing through a source it may help me very much
> if I could see at the `def' line if it's a regular function or a
> generator.
[Paul Prescod]
> I see this as an important point. It would be redundant to add a
> generator modifier to functions but I think that that redundancy would
> actually help people. It would help new users to understand that a
> generator is a *type of function*, *determined at compile time* and not
> a behavior of a function, determined at runtime.
def xyz(i):
return abc(i)
can also return a generator-iterator in 2.2, and it's what the function
*returns* that's important to users. There's no way in Python to
communicate that apart from docstrings and comments, and PEP 255 doesn't
change that.
> It would help even expert users to spot generators in code.
Unlike most of the participants in this discussion <wink>, I've used
generators heavily, and I don't *care* where the generators are in the code.
This is like saying that functions returning integers should be declared
"defint" instead, or some such gibberish. Ya, maybe once in 10 years you're
going to want to find all your functions that return ints; same thing with
generator-functions (a proper subset of the set of all functions that return
generator-iterators), except they're already much easier to find.
> It would help documentation-generation programs like pydoc to "flag"
> generators without massive complexity.
Static typing would be much more effective for this, and not limited to a
single obscure case.
> It would help all of us ensure that our code is inline with our
> intentions. And it doesn't seem like it would hurt anything.
Drawing pointless distinctions is a distraction -- whether a function is or
isn't a generator-function simply isn't interesting for most people, most of
the time.
More information about the Python-list
mailing list