From: Rob Biedenharn Date: 2007-06-12T23:26:15+09:00 Subject: Re: a matter of style On Jun 12, 2007, at 6:59 AM, dblack@wobblini.net wrote: > Hi -- > > On Tue, 12 Jun 2007, Anthony Martinez wrote: > >> On Tue, Jun 12, 2007 at 03:10:49AM +0900, Bas van Gils wrote: > >> As well, reserve the { } form of blocks to one-liners. > > That's going to depend partly on whether you run across the > (relatively rare) case where the precedence difference between {} and > do/end actually matters. There are also some interesting ideas on > record (see archives) involving blocks with side effects vs. blocks > that just calculate. But I can't remember which is supposed to be > which :-) > > > > David > > -- > * Books: > RAILS ROUTING (new! http://safari.awprofessional.com/9780321509246) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) Jim Weirich tends to be an advocate of that convention: use do-end for blocks that are "just blocks" and {} for blocks where the value of the block is to be used. If you ever see any of Jim's code that uses Builder, this convention is quite apparent. The problem of the higher precedence of the braces can often be side-stepped by parenthesizing the method arguments preceding the {block}. This is one of the reasons that the do/end form is recommended for Rakefiles so that the need for ()'s doesn't distract from the DSL-ish feel of the task method. I tend to merge this idea with the one for one-liners and prefer {} in irb where the code isn't being saved anywhere and almost never use {} in ERb templates where the opening and closing of the block are in separate <% %>'s. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com