From: Gavin Sinclair Date: 2003-07-31T23:37:36+09:00 Subject: Re: Ruby could be wildly more popular if it had ... On Thursday, July 31, 2003, 8:58:48 PM, Robert wrote: > "Arthur" schrieb im Newsbeitrag > news:16e0bc53.0307310222.11587422@posting.google.com... >> "Gavin Sinclair" wrote in message > news:<60107.203.185.214.34.1059543084.squirrel@webmail.imagineis.com>... >> > > On Tue, 2003-07-29 at 22:30, Robert Klemme wrote: >> > > >> > >> My solution is to use {} for one line blocks and do..end for more >> > >> complicated things. >> > > >> > > I tried this style for a while. But then every time I added lines > to a >> > > one-line block, I had to change {} to do/end. >> > > >> > > Today I normally used {} on all blocks, except in Rake files. >> > >> > >> > My take is: {} are for functional blocks; do..end for procedural > blocks. >> > That shows me which expressions are important for their results, and > which >> > are not. >> > >> > Gavin >> >> >> This sounds very interesting. Can you expand upon this a little? >> What do you take as the difference between procedural blocks and >> funcitonal blocks? Can you provide an example? > I guess he means > (0..10).each do |i|; puts i; end > (0..10).map {|i| i+i} > robert Precisely. Some blocks are called to _do_ something, and some are called to _evaluate_ to something (or, to _return_ something). That's a high-level difference that is important to understanding high-level program flow, so providing a visual signal in the code is some help to me. It turns out that most functional blocks are one-liners, like: set.find { |e| e.satisfies condition } But then you get some larger ones: set.map { |e| if something e.x else e.y end } do...end looks silly on one line, though, so I always spread that out: people.each do |p| process(p) end I figure the concept there is worth devoting three lines to. Cheers, Gavin