[Python-ideas] Does jargon make learning more difficult?

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 22 19:02:27 EDT 2018


Rhodri James wrote:
> This, by the way, is why think using the same syntax for function 
> definition and generator definition was a mistake.

I think I remember arguing the same thing back when generators
were being devised.

But there are arguments the other way too. From the outside,
a generator is just a function that returns an iterator --
the fact that it works by yielding is an implementation detail.

When you write an ordinary function that returns an iterator, the
fact that it returns an iterator needs to be conveyed some other
way, such as by its name or documentation. if you can do that
for an ordinary function, you can do it for a generator just as
well -- and probably should, so that you can tell what it returns
without having to look at its definition.

If the name of the function indicates that it returns an iterator,
or there's a docstring at the top what says so, then you won't
be surprised when you find a yield in it somewhere.

-- 
Greg


More information about the Python-ideas mailing list