Ferenc Kovacs wrote:
I can't really follow your sql example, but let's try this another way: You understand how Iterators work, right? (http://php.net/manual/en/language.oop5.iterations.php http://www.php.net/manual/en/class.iterator.php) The proposed generator implementation works the same way from the consumer/caller perspective. They call a function, which returns them a Generator object, which implements the iterator interface, so the caller can iterate over the returned object. In the background, the original function body acts as the implementation of the next() method of the iterator inteface, and the yield keyword is used to mark the end of each next() call. Does this make it more clear to you?
I've just gone back over the rfc and I probably understand now why I was getting confused. Actually it really does irritate that the first 'example' on the page is simply the wrong way of doing it anyway. We should not be propagating bad code like that and using it as justification for something new just got my back up from the start. The extra "Why not just use callback functions?" irritates more because again it's another poor example. Drop the callback altogether and just add a call to process the data using a suitable object ...
Then the next example is an 'iterator' ... which you are right ... I do not appreciate either, because they require an insane amount of overhead for what would be easy if the first example had been done right! I did try them, in the past, but the overhead outweighed any advantage and I can't find them in any of the projects I work with apart as a blank frame in ADOdb ... which nobody seems to use.
So I'm working from the wrong base simply because interators also introduced too much overhead for no gain. Now we are trying another fix to make iterators work better? I suppose the next step is simply using 'yield' without iterators? The iterator magic is only used to hide some of the process flow where a simple object might work better.
I CAN actually see where the use of yield might work, but I am probably simply to stuck in my ways. Niktia's "A concrete example, which was actually my initial motivation to write the generators patch:" is probably another good example of why iterators are simply wrong more times than they are right?
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php