Re: polymorphism and dynamically typed languages
- From: Ron Jeffries <ronjeffries@xxxxxxx>
- Date: Mon, 18 Apr 2005 11:39:44 -0400
On Mon, 18 Apr 2005 02:16:07 -0700, cstb <jas@xxxxxxxxxx> wrote:
>It appears (to me) that each of you is being a bit strict
>with the terms, and possibly missing one another on the way by.
>Or I've missed 'em both.
>>>Now in static typing languages, I most often see inheritance /from an
>>>interface/, which isn't really inheritance at all in my book, just a
>>>way of declaring what methods an object has.
>To be fair, I expect you see inheritance of implementation, too.
>But when you see "interface inheritance", it seems, well, superfluous?
I did say "most often", since I do see inheritance of implementation
as well. No intention to be unfair. :)
In languages that want to do static typing down to the method level,
interface inheritance isn't really superfluous, as you have to have
some way to name the protocol to be adhered to. I do think that the
whole idea of static typing might be superfluous, but that would be
a different topic.
>> In dynamically typed languages inheritance of interface is not
>> necessary to get polymorphism.
>Right. (But is it, strictly speaking, *neccessary* in Java?)
As far as I know, it is. Java won't let you pass an object to a
method unless it is of the right type. There's no practical way
around that, though I suppose you could pass everything as Object
and use reflection to call the methods.
>> So polymorphic structures rarely make use of inheritance.
>Whoops - just because inheritance isn't *neccessary*, one cannot
>automatically conclude that it is rarely used. Seems to me it is
>used *most* of the time. Of course, this is a relative term -
>my 'most' might look awfully rare when compared to 'always'.
I meant inheritance of implementation there, I think. Perhaps I stated
my position more strongly than it deserves as well, but what I mostly
see in Java and C# is inheritance of interface, and very shallow
implem/entation inheritance trees, and often none at all.
>> On the other hand, both kinds of languages use inheritance
>> of implementation to share code.
>Here again, I think, is the crux - motivation.
>Ron says 'to eliminate duplicate code', whereas
>Bob says 'to share code'.
>I find that people using static languages more often
>describe 'subclassing from' something else, as a starting point,
>whereas people using a dynamic language more often describe
>'eliminating duplication', or 'pushing up commonality', as
>a relative end point.
I suspect that's more of a viewpoint that has come to us from the
extreme programming heritage, where in using incremental development,
we morph the code. In earlier days I might have spoken differently.
There is an aspect of intentionally reusing something in "subclassing
from" and of discovery in "eliminating duplication" or "pushing up". I
would, again, attribute that to the more incremental outlook that some
of us now take to development.
>The result is very similar, yet the initial motivation
>which gets us there seems to be described very differently.
The result is similar but different, especially in Smalltalk. In
Smalltalk, in principle, you can refactor up into the base
superclasses if you want to. In Java and C# you cannot ... in fact
there is a deplorable tendency to declare base classes in such a way
as to make it impossible to subclass from them, and of course it's
usually entirely impossible to add things to a vendor-provided class.
>Does this description work for either of you?
Pretty well. Where are we now?
I'm giving the best advice I have. You get to decide if it's true for you.
- Prev by Date: Re: a UML tool light on resources
- Next by Date: Re: a UML tool light on resources
- Previous by thread: Re: polymorphism and dynamically typed languages