>
> Suggestion:
>
> For a generator, rename the keyword "function" to ... "generator" or
> something like that. Example:
>    generator hugo()
>    {
>      yield ...
>    }
>
> As Nikita pointed out, having a T_GENERATOR token will cause side-effect
problems from namespace collisions.  This is a concern any time you add a
keyword to the PHP parser.


> Fact: yield/generators is more or less complicated, this shouldn't be
> changed - it's a proven concept.
>
Speaking of parse errors, I'm having trouble parsing this line.  I *think*
you're saying that generators are just complex things and that's the way it
should be.  I... guess I agree, though I have a lower opinion on the
complexity of generators.  Seem like a fairly straightforward concept to
me.  They are certainly proven concepts.

Fact: yield makes functions some kind of "different".
>
Yes, they turn normal functions into continuation functions (functions
which can be exited and reentered dynamically).


> Fact: It doesn't matter how it is implemented in other languages,
> because we talk about PHP and not other languages.
>
Disagree somewhat.  Part of PHP's ease-of-use it it's similarity to other
languages so that a developer working on C or Perl or Java or
what-have-you, can look at PHP code for the first time and have a pretty
good idea of what's going on.  Mirroring existing implementations should
certainly be a consideration for that purpose.  Not the end-all decider,
but a consideration.


> Fact: This is also good style in general: Call the things what they are.
>
I'll grant this point has merit, however it has two counter-arguments.  (1)
T_GENERATOR naming conflict mentioned above. (2) Generators *are* still
functions, so the name "function" isn't a misnomer.  They're just a special
type of function similar to how methods are special types of functions, but
we still label them as "function".


> Fact: as PHP-developer we must try to avoid making things more
> complicated, because this is one of the best features of PHP.
>
Agreed.  And a generator is far less complex than a full iterator
implementation.  Further, continuation functionality is far less complex
than building in loop counting logic to an iterator's next() method.


> Fact: it's easy to implement a new keyword  into PHP for that case
>
False. See above.


> Experience: Most PHP programmers will have problems to understand
> generators because it is a function that generates an iterator...

something magic <eyesroll> they never heard of before.
>
Fact: PHP's manual is the best in the industry.  PHP developers know this.
 PHP developers are smarter than you give them credit for.


> Experience: generators/yield can't be explained on one page. Much
> programmers will never ever read so much docs. :)
>
The core of what a generator is can be explained in a single paragraph with
a few examples - Just like nearly every page in the PHP manual.  If we
can't give PHP developers that much credit, then we should shut the project
down now.


> Experience: good features are self-explaining. A function which
> returns an iterator because of a simple word in it's body is not.

A developer who's never seen the yield keyword before need only learn what
it is once.  http://php.net/yield  Problem (to be) solved.


> Experience: They will make stupid mistakes, because they mix yield
> function with normal functions.
>
And the compiler will slap them for it.


> Experience: They will make stupid mistakes, because they will look for
> "return" instead for "yield".
>
And they won't find it, but hey look, what's this yield thing, I wonder
what that does: http://php.net/yield


> Experience: Not using the same name will remove a little bit pressure
> from "busy" programmers
>
Developers who work with other people's code (and that's who you're talking
about) routinely have to spend time understanding the purpose of a given
function.  To assume that one can pretend to understand a function without
having seen and questioned an unfamiliar keyword like "yield" is ridiculous
from the outset.

If this hypothetical developer wants to understand the function, they'll
see it's got yield and learn that's what makes it a generator.   If they
don't want to understand the function, then putting up a big sign isn't
going to help the matter whatsoever.


> Experience: The current concept dosn't "feel right" for me. I like to
> listen to my belly in those questions, because he is in most cases
> right. With the change I suggested he stops grumbling.
>
Fair enough.  Unfortunately, for the reasons stated above, it's just not
that simple.

Reply via email to