Re: polymorphism and dynamically typed languages



On Mon, 18 Apr 2005 02:16:07 -0700, cstb <jas@xxxxxxxxxx> wrote:

>Bob, Ron,
>
>Intereting exchange.
>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?

Regards,

--
Ron Jeffries
www.XProgramming.com
I'm giving the best advice I have. You get to decide if it's true for you.
.



Relevant Pages

  • Re: Type regimes - terms and themes (Was: Naive, possibly silly question [LONG] )
    ... Well, if we leave it just to Uncle Bob and comp., this newsgroup doesn't ... *has to* use inheritance in a statically typed language. ... in java pretty much all GUI classes derive from an object ... This claim is further false and misleading even for mainstream languages ...
    (comp.object)
  • Re: Inheritance and Polymorhpism (getting back to the point)
    ... >>replaced with an inheritance hierarchy. ... > languages that, for the purpose of this discussion, we shall call ... base class will force a recompilation of all derived classes, ... in the tasks window, courtesy of static typing. ...
    (comp.object)
  • Re: Modula-2 vs. Oberon-2
    ... This is a bad substitute for real modules that most OO languages are ... the recursive call patterns produced by inheritance and object ... I believe that comes close to your idea of a "opaque type"? ...
    (comp.lang.modula2)
  • Re: Noun Oriented Thinking Considered Harmful
    ... I like Delphi because it doesn't force me to use classes or interfaces to ... Object Pascal and entirely object-oriented languages like Java and C#. ... again need one or more diagrams - UML diagrams showing inheritance trees, ... programming paradigm introduced in Pascal and perfected in languages like ...
    (borland.public.delphi.non-technical)
  • Re: Another OO Problem (and thanks for the input I received so far)
    ... >> I think I would call this the Java immutability problem. ... > Can you name a language with inheritance that is not OO? ... Just about all procedural languages have for..next loops or the ...
    (comp.programming)