[Edu-sig] re: Does edu-sig extend to Jython

Patrick K. O'Brien pobrien@orbtech.com
Sun, 18 Aug 2002 16:19:34 -0500


[Arthur]
>
[example snipped]
>
> Now I think I understand it is mostly Python's dynamic
> nature that makes this kind of facility difficult (impossible?)
> to implement as a built_in language feature.

Yes and no. It certainly isn't Python's default mode of operation to care
too much about the type of an object, versus what an object is capable of
doing.

> And I think I understand the possiblities, at least in general,
> of a lot of isinstance or type testing of *args - but its ugly, and
> error-prone - at least, that is, up until the point at which the rest of
> the design is sufficiently stabilized so that I know
> *exactly* what it is I want to be testing for and am not
> expecting any more changes to be coming down the pike.
> Seems to be the nature of my approach, that I never quite get
> to that point.

Checking via isinstance() shouldn't be too difficult. But it may not even be
necessary.

> So, I am beginning to try to digest the meaning and significance
> of "multimethods" - for which there are Python modules.

I found one at http://www.sff.net/people/neelk/open-source/Multimethod.py.
Is that the same one you are talking about?

> I guess then my question, which I am pursuing, is what are
> multimethods, and how might they relate to the issue I am
> trying to deal with?

Multimethods appear to be exactly what you are asking for. But I'm not sure
they are the right thing to be asking for, if you know what I mean. :-)

Let's look at your example of an Intersection constructor and the variations
you want to support:

    Intersection(plane,line)
    Intersection(line,plane)
    Intersection(line,line)

What I'd ask is why do you need to know the types of the two parameters? At
what point does it matter? What method(s) of Intersection need to function
differently in each of the three cases?

I think we need to see more code to figure out whether this can't be handled
without too much regard for object types. And even if some type checking
needed to take place, multimethods seem like overkill to me.

--
Patrick K. O'Brien
Orbtech
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------
Web:  http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
-----------------------------------------------