On Saturday 05 June 2004 21:05, John W. Long wrote:
> Sean O'Dell wrote:
> >On Saturday 05 June 2004 13:30, Dave Thomas wrote:
> >>Then it's not your problem! Code on, young turk.
> >
> >No, it IS my problem. My code quietly does some really undesired things
> > when non-hash-like objects get to this one point in code. I hate this
> > attitude about typing. I know you mean well, and it's been talked out to
> > death, but I don't buy the whole thing about "if it has the methods, it
> > must be fine." It's clearly NOT fine. If an array or a string, both
> > which have the [] methods I need, get to this one place, I drop a whole
> > branch of data being passed around. The ideal is to catch it as an
> > error, and remedy the situation by finding out how the data came in that
> > way in the first place and prevent it, or perhaps just detect it and
> > perform some special case. As it is, I can't tell for sure when an
> > object really DOES act like a hash.
>
> The problem Sean is that even if you know the method has the right
> signature you can't guarantee it has the same functionality. It remains
> an exercise for the person that wrote the contorted object and is
> passing it in to figure out how to make it work with your code. If it
> needs to be more hash-like, then let him figure out he needs to pass a
> hash. If he can get his weird object to work without it actually looking
> or acting like what you think a hash should look like, why penalize him
> because he doesn't implement it in a certain way?
That's just a confidence issue. I don't care if the object coming in is
broken. I'm not concerned about catching objects which are implemented
improperly; that's actually very rare. If an object had a signature that
said "I am a hash-like object" that would be fine for me. Duck typing and
checking respond_to? are completely inadequate, and it seems like people
argue those points because Ruby offers nothing else and so what are you going
to advocate? It's those two or rolling your own interface identification
system, which I think is cheesy; that sort of functionality should come from
the framework.
Sean O'Dell