From: Jim Weirich Date: 2004-05-02T07:34:45+09:00 Subject: {} VS do/end styles (was: Ruby Newbie - When do I use do/end, when {}?) Mark Hubbart wrote: > While there is some amount of preference involved, there is a general > rule that most Ruby programmers (and matz, I believe) agree on: brackets > for one-line blocks, do...end for longer blocks. ie: I've heard that general advice, and even followed it for a while. I finally gave up on it because many one liners grow into multiline blocks, and it was just annoying to switch from {} to do/end when that happened. Plus the style choice wasn't conveying any additional information, so I dropped it and went back to a "whatever looks good" style. Just recently I've been trying out the following guidelines: o If the block returns a value, use {} o if the block doesn't return a value, use do/end So far I like the way it is turning out. The style choice helps to convey some of the intent of the programmer. I offer it here for others to try. If they like it, fine. If it doesn't work for you, no problem either. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)