From: David Alan Black Date: 2001-11-29T23:50:49+09:00 Subject: [ruby-talk:26902] Re: short article draft for review Hi -- On Thu, 29 Nov 2001, Tobias Reif wrote: > I wrote: > > Yeah, like that :-) My advice would be to include an example that > > involves an interator (without recursion), and then, if you think it's > > important, a recursion example. > > > But that's what I did: > An iteration example: very simple, without blocks or recursion; > then comes an example of recursion: with blocks passed around. > > Or did you mean > 1. iterator with block > 2. recursion > ? > > I don't see the significant advantage there. I'm just thinking that the "for" loop doesn't show off anything unusual or (particularly) powerful about Ruby. I guess I'd recommend something like: def my_iterator i = 0 while i < 10 yield i * 2 i += 1 end end my_iterator do |result| print "Next result is: " puts result end Combining the recursion example and the (what I'm calling :-) iterator example might be overload. Also recursion, like "for" loops, isn't a particularly striking feature of Ruby -- not that it shouldn't be mentioned, but I think it's good to isolate the write-your-own-iterator facility so as to show it off to best advantage. > > One other thing: In method definitions, putting the arg list in parens > > might be a good idea. (Personally I dislike the non-paren look, > > > me too > > > but > > here I'm thinking of people who might like it ultimately but might be > > confused by it initially.) > > > I guess most people coming from other could like less parens. Possibly, but I think with an arg list that's already got several possibly unfamiliar idioms in it (namely var=default and &block), it might be clearer to put the parens around it. I think it's also a majority practice in Ruby. Whenever I see non-parens, I think, "Oh, one of those people who don't put parens around arg lists in method definitions" :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav