Iñaki Baz Castillo
2/26/2009 2:30:00 PM
2009/2/26 lasitha <lasitha.ranatunga@gmail.com>:
> On Thu, Feb 26, 2009 at 1:24 AM, I=C3=B1aki Baz Castillo <ibc@aliax.net> =
wrote:
>>> It also can hide problems that you won't know that you have. For
>>> example,
>>> =C2=A0 =C2=A0myvar =3D nil
>>> =C2=A0 =C2=A0othervar =3D 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 Fix=
num.
>> 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. =C2=A0That is not to say it's always wrong, just always at lea=
st
> a little smelly :). =C2=A0Particularly 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. =C2=A0It 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.
--=20
I=C3=B1aki Baz Castillo
<ibc@aliax.net>