From: Chris Pine Date: 2006-02-23T00:17:42+09:00 Subject: Re: Understanding ruby? need help > > I wrote a tutorial that talks, among other things, about a somewhat> > different approach to understanding blocks and procs:> >> > http://pine.fm/LearnToProgram/?Chapter=10>> Chris, I can't see "yield" mentioned on that page. Is it just me, did I> overlook it? Is this intentionally? Yep. On the next page (Chapter=11), I talk about, among other things,yield. But I wanted to bring it in later as another way of doing it. > I mean, "yield" would be the first> thing that I'd describe on such a page; IMHO it's the default way to go when> passing blocks to methods (it's also the fastest AFAIK). Default way to go for an experienced programmer to use? Or for anon-programmer to learn? Very different situations. :) > I only use &block> if I have to store the block in a variable and / or have to pass it on to> another (recursive) method call. Me, too... unless I'm teaching someone about it, because "yield" justthrows people off in my experience (not just my personal experience,but my experience in teaching others). > If you look at the block as anonymous function it's clear that one needs a> special syntax to invoke it (can't use the name). That's exactly what> "yield" does. Well, there's "anonymous" (like &block), and then there's *invisible*,like what yield is calling. There's a big difference. I'm justtrying to make it visible, which is an important step on the way tounderstandable. Plus, passing a function around, and calling a function... thesethings are extensions of what the reader has already learned at thatpoint. "yield" is something totally new. Better to describe this interms of something the reader is more familiar with first; then I canjust say "yield is a magical shortcut". Because it sort of it, right? It's magical, and magical is (among other things) weird. That's myhypothesis, anyway. :) Yield: it's something you do to traffic with the right of way. It'show many cookies your recipe is "supposed" to make if you don't eatany of the dough. I can see the (imho, weak) analogy toprogramming... but I think that describing what is going on in asplain of terms as possible is the best way to teach this. In any case, the PickAxe does it the other way, so hopefully we haveevery learning style covered. :) Chris