Jump to content

Talk:Subtyping

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Cjoev (talk | contribs) at 15:55, 24 March 2005 (explaining myself). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

I am not implying that the author has no idea at all, but this article makes little sense. I am especially puzzled by the discussion of subclasses. My guess is that he is confused with the idea of typing and implementation. A subtype is more of typing issue, whereas subclassing is to create a new class based on an existing one. Am I the one who is missing something? (Of course, the previous version was not good either.) -- Taku 21:00, Mar 23, 2005 (UTC)

I'm sorry if what I wrote does not make sense, but I think it can be fixed. We may agree more than you think about subclasses. That paragraph was not supposed to be a definition, but an example. It is a fact that in C++, Java, C#, and just about every other statically-typed class-based object-oriented language I can think of, if A inherits from B, directly or indirectly, then A is a subtype of B. (To be pedantic, if the class A inherits from the class B, then the type A is a subtype of the type B -- in the languages I'm speaking of the distinction between classes and types is unfortunately blurred.) Perhaps it is a design flaw in these languages that they link subclassing and subtyping so closely (I hold this opinion), but nevertheless it's a very familiar phenomenon.

One place where I may indeed have crossed the line into implementation is in the inclusive/coercive distinction. Thinking about it again, of course this is a matter of implementation -- I was temporariliy distracted from this by the fact that subtyping in some languages is almost trivial to implement inclusively, while subtyping in other languages is almost impossible to implement inclusively and must be coercive (int <: float is a good example).

The nominal/structural distinction is, I think, well known. It is also very important, because type theorists tend to work almost exclusively with structural theories of subtyping but many programming languages (notably class-based OO languages, as I discussed) use nominal subtyping. The terminology may not be standard, but if it's not then I don't think there is any standard terminology; perhaps the words should not be in boldface.

My personal opinion is that the (admittedly, extremely common) usage of the word "polymorphism" to describe the use of subtyping to make one's code more flexible (as in your example) is incorrect. Certainly, it is at best one form of polymorphism. -- Cjoev 15:55, 24 Mar 2005 (UTC)