On Wed, Aug 22, 2012 at 2:10 PM, Lester Caine <les...@lsces.co.uk> wrote: > 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?
Hi Lester! You may want to look through this presentation: http://www.dabeaz.com/generators/Generators.pdf The RFC is a technical document outlining the details of the implementation; it isn't well suited as an entry-level tutorial on the topic. The above presentation might do a better job explaining the concept and its uses. But I think I understood your main problem with generators now. Generators are very useful for the creation of reusable and pluggable components. You don't seem particularly fond of that kind of programming and prefer hardcoded and tightly coupled implementations. In that case generators probably won't give you anything. But they won't hurt you either ;) You can still practice the One Big Method style of programming. Thanks, Nikita -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php