Jay Levitt wrote:
> On Sun, 7 Oct 2007 03:44:20 +0900, Greg Willits wrote:
> 
>> Ah, OK. Strange structure. (rhetorical Q:) Why read through all the 
>> do_stuff if it isn't going to matter by the time you get the IF?
> 
> Rhetorical semi-answer (by argument to consequences):
> 
> Allowing the form
>   puts "Got to line 123" if debug_mode
>   do_something important
> 
> lets you have more compact code, at the potential expense of 
> readability.
> 
> For readability's sake, I usually follow the guideline "don't use that 
> form
> unless the main body of code is the common path".  That is, I wouldn't 
> use
> it for debug statements, because they're usually not executed, so you 
> spend
> a lot of time reading code and then realizing it didn't get executed 
> after all.

Thanks for piping up and saying "don't use that." I agree :-)

All this is exactly why

   condition ? do_stuff

is very useful. Compact. Readable. Logical. Efficient. Even if it is not 
a true ternary.

I have plenty enough experience in dynamic, reflective, OO programming, 
to figure out the bulk of Ruby, but Ruby does seems to have its own way 
of approaching some things compared to my experience.

I know there's a book called The Ruby Way -- does it tend to address 
these kinds of usage idioms where "method 2 out of 4 tends to be the way 
most people do it"?

-- gw

-- 
Posted via http://www.ruby-forum.com/.