From: "Iñaki Baz Castillo" Date: 2009-02-26T23:29:52+09:00 Subject: Re: Using "rescue" inline 2009/2/26 lasitha : > On Thu, Feb 26, 2009 at 1:24 AM, Iñaki Baz Castillo wrote: >>> It also can hide problems that you won't know that you have. For >>> example, >>>    myvar = nil >>>    othervar = myvar.downcase rescue myvar >>> Did you want to set othervar to nil also? >> >> Not exactly, but myvar could be a Fixnum so othervar would also be a Fixnum. >> But if myvar is a String then I want othervar to be the same String but >> downcase. > > This may be stating the obvious but code that branches based on type > is smelly.  That is not to say it's always wrong, just always at least > a little smelly :).  Particularly if you find multiple places in the > code having to deal with Fixnum and String conditionally. > > The inline rescue slightly obscures the conditional but the smell > remains.  It may be worthwhile reconsidering whether you really want > myvar to hold disparate types. > > I would also reiterate Rob's concern that this rescue could easily > hide some unrelated bug (mvay being nil being the most obvious). > > These two concerns would be enough for me to reconsider, but as usual, > it all depends on context. Yes, you are right, I'll consider it. Thanks a lot. -- Iñaki Baz Castillo