Object: Identity vs. Environment
Nevin Pratt
nevin at smalltalkpro.com
Thu May 29 12:55:08 UTC 2003
Joel Shellman wrote:
>The cleaving you are referring to then is 1) every object that is a foo, and
>2) every object that is not a foo, right?
>
>However, that same distinction can be made for any class: 1) is an instance
>of MyClass, 2) is not an instance of MyClass.
>
>
>
No, that is not the same distinction at all. The only way it would be
is if:
(1) "type" was a structural type rather than a behavioral type (i.e.,
a type is defined by it's internal structure rather than its behavior)
and
(2) the statement "every object that is a foo" was meant to denote
such a structural type "foo".
For Smalltalk, assertion #1 is always false. For Smalltalk, "type" is
not determined by internal structure, but rather the "type" of something
is determined by its behavior. I refer to this as "behavioral typing"
rather than "structural typing". For Smalltalk, internal structure of
the receiver is irrelevent.
Note, however, that for a static language, #1 is always true. Static
languages choose to define "type" exclusively by internal structure.
For such languages, if one object has the same or a superset of the
internal structure of another object, it is considered to be of the same
"type". Furthermore, static languages control internal structure via
inheritance, which means the meaning of "type" is explicitly tied to the
inheritance tree. In other words, for such languages, "class == type".
But this is not true of Smalltalk, which doesn't use structural typing
at all, but instead uses behavioral typing to define a "type". Which
means that "class ~~ type" for Smalltalk.
And for static languages, #2 is occasionally false. The message #isFoo
(used to denote that the object is a foo) is not necessarily meant to
denote a type "foo". At least, not if structural typing is being used.
For static languages, the #isFoo idiom is often used to try to graft a
modicum of behavioral typing on top of a language that doesn't
intrinsically support behavioral typing.
For static languages, saying that #2 is occasionally false also means
that #2 is often true, which means that for a static language (ala Java
or C++), you did indeed name the same distinction for many of the cases.
And in my opinion, for static languages, your distinction is indeed
true for the overwhelming majority of the cases.
But for Smalltalk, it is not the same distinction at all.
Nevin Pratt
Bountiful Baby
http://www.bountifulbaby.com
(801) 992-3137
More information about the Squeak-dev
mailing list
|