Re: Re: Generators in PHP
| From: | Larry Garfield | Date: | Thu, 09 Aug 2012 02:25:49 +0000 |
| Subject: | Re: Re: Generators in PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62091@lists.php.net to get a copy of this message | ||
On 07/27/2012 07:23 AM, Lester Caine wrote:
Nikita Popov wrote:Anthony had a very good writeup on generators and how they compare to iterators last week: http://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html I think that does a good job of laying out the case for generators as "low-effort iterators". I still think the syntax feels clunky to me, but that's probably because I'm not used to it from other languages. One question, though: It looks based on the voting like finally {} blocks are going in. So... what should happen in the following situation: function stuff() { try {In a different way ... Is the only thing that changes the 'function' into a 'generator'I'll ask again since no one has answered ...the call to process the data with 'yield'? ( That would bereplacingSQL procedure ) ... So how DOES an IDE work out the flow in order to correctly check that variables are defined? As always, my IDE provides a lot of 'sexy' stuff so that I don't'SUSPEND' in anhave it built in to the language, and I still can't see how a lotneed tobeing loaded in helps with performance which is the only thing thatof what isinterested in. Performance wise why is yield better than just directly calling a function to handle the data?I amLester Caine and Alex Aulbach, may I ask you to continue this discussion in a separate thread? I am really interested in constructive responses about the generator RFC, but your discussion is generating a lot of noise, which makes it very hard for me to pick out the few mails that are of interest to me. If you could open a new thread (like "Generator keyword") it would help a lot.Nikita - I am looking for a well reasoned argument as to why generator has to be added at all! 'Just because it can be' is not a valid argument, but perhaps you could add to the RFC the performance implication or advantage of what is being proposed. That would at least be some comparison with the current methods of doing the same thing?
foreach (range(1, 100) as $i) {
yield $i;
}
}
finally {
print "All done";} } Does "All done" get printed once, or 101 times? Similarly: function things() { $i = 1; try {
while (true) {
yield $i++;
}
}
finally {
print "All done";} } That will run indefinitely. So will "All done" ever print, or does that finally become unreachable? (I have no clue what the behavior "should" be in these cases, just that it should be sorted out sooner rather than later.) --Larry Garfield