From: Jim Weirich Date: 2004-02-15T03:08:52+09:00 Subject: Re: Simple litle style question David A. Black said: >> def simpleExample(t) > > I prefer "simple_example" :-) Amen! > And, just for fun, there's also: > > def simple_example(t) > block_meth { if t == 'forty-two' then 42 else 0 end } > end > > def simple_example(t) > block_meth { t == 'forty-two' ? 42 : 0 } > end I prefer either of these one-liners over the longer examples. They succinctly express the heart of the calculation without any extra noise. > (I won't bother with the "t == 'forty-two' && 42 || 0" one :-) Good Heavens! Thank you. Where the other oneliners express the logic directly, this one tends to cloud it (IMHO). >> i.e. do you explicity declare a return variable and put that variable >> right before the 'end' or do you rely on your audience being smart >> enough to perceive what the return value is going to be? On the short examples given, I would let Ruby be Ruby and just have the last (and only) expression be the implicit result of the function. If the function is longer (more than one expression), then I might use a return variable, especially if the expression I wish to return is the last expression only by coincidence. When I use a return variable, I _always_ spell it "result", and only use the name "result" for return variables. -- -- 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)