On 3/2/07, Adam Kennedy <[EMAIL PROTECTED]> wrote:
> 99.999% of the time you do not want to really know how something is
> implemented, you want to remain ignorant.

I concur, which is what really pisses me off them
IO::String->new(\$string)->isa('IO::Handle') returns false, because the
author believes in duck typing over actually having isa describe the
interfaces.

This comment lead to do some thinking about perls typing and OO
structure and why people seem to have a lot of trouble agreeing on
things like this.

A "type" in a language like C is a specification of data
representation in memory.

In an OO language like C++ this gets extended to be a data
representation in memory plus a set of methods that represents an
interface.

But...

In Perl the memory organization is orthagonal to the interface.

So we have immutable types like SV's, AV's,HV's, CV's, FORMATS, IO, etc.

And then through blessing we can associate the same set of methods to
any or all of those types.

So when you try to fit the Perl model into the C++ model something has to give.

The only way to properly map the perl level concepts to C++ is to say
that a C++ type is a perl type+a perl class.

But because of the history of ref(), and isa() and the way 'type' is
misused in the perl literature the distinction is blurred. Some people
want to say "are you something I can deref as a particular type AND
has an interface I know how to use" and some people JUST want to say
"are you something that has an interface I know how to use". Both
questions are reasonable and mutually exclusive. One routine cant do
both.

So for instance to me it seems to reasonable for IO::String to say, no
I am not a IO::Handle. Its data representation doesnt use a IO object
so its not an IO::Handle, even if it does provide the same method
interface.

isa() is to some a method that asks the first question, but to others
is asks the second question.

Now if there was an ->implements() utility function as well as the
->isa() funcation, then I think IO::Handle would contrive to ensure
that IO::String->new(\$string)->implements('IO::Handle') would return
true even though IO::String->new(\$string)->isa('IO::Handle') would
not. (Im not sure if this is the same as chromatics proposed 'does'
function).

Anyway, thanks. The comment on "duck typing" sorta made all this click
for me in a way it hasnt before.

Cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Reply via email to