From: David Harmon on
On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
<ben(a)morrow.me.uk> wrote,
>
>Quoth "Newsgroup only please, address is no longer replyable." <bad(a)example.invalid>:
>> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
>> <ben(a)morrow.me.uk> wrote,
>> > In simple terms, an object is just a
>> >refrence with a bit of magic attached.
>>
>> "bit of magic attached" isn't simple terms; it's pure obfuscation.
>
>If you say so. Would you rather I said 'an object is a reference to a
>SV that is at least a PVMG, with SvSTASH set to point to the stash of
>the class it's blessed into'?

All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
me as "magic".

> Perhaps you would like to provide a simple
>explanation of Perl objects, suitable for someone who hasn't met the
>concept before?

Perhaps I would, when I understand it. For now about all I get is that
the object is connected in some hidden way to the module it is "blessed"
into, so that one of the subs in that module can be located and called
when the object method call syntax is used. But that is guesswork,
coming mostly from what I think would have to happen for OOP to work,
(and coming from C++) and not from anybody's explanation.

Either that, or it is wearing a new magic hat and I have no idea what
that means. In my experience, with programming there is always a
non-magic explanation, once you find it.

Speaking of "blessed". When I was five years old, I asked a nun what
the difference was between holy water and regular water. After the
first attempt at an answer, the answer became "It's a mystery." She got
a bit upset before I figured out that "It's a mystery" means "don't ask
me any more questions." I think "magic" means the same thing, along
with "blessed", and I think those are all obfuscation.

And yes, I would prefer "SV", "PVMG", and "SvSTASH" as at least those
suggest that searching for those keywords might eventually lead to the
explanation, whereas "magic" surely will not.

From: Tad McClellan on
David Harmon <source(a)netcom.com> wrote:
> On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
><ben(a)morrow.me.uk> wrote,
>>
>>Quoth <bad(a)example.invalid>:
>>> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
>>> <ben(a)morrow.me.uk> wrote,
>>> > In simple terms, an object is just a
>>> >refrence with a bit of magic attached.


In simple terms, push down on the right pedal and the car goes faster.


>>> "bit of magic attached" isn't simple terms;


Yes it is.


>> it's pure obfuscation.


On purpose.

And that is a good thing, not a bad thing, when teaching.

If you overwhelm the student with details they will likely miss
out on grasping the important fundamentals.

So you give the simple version first, and elaborate after they
have digested that.


>>If you say so. Would you rather I said 'an object is a reference to a
>>SV that is at least a PVMG, with SvSTASH set to point to the stash of
>>the class it's blessed into'?


Would you rather I said depressing the pedal sends a SIGGAS to
the ECM, which increases the air-fuel mixture to move the engine
higher on its horsepower curve?


> All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
> me as "magic".


Yet less simple.


>> Perhaps you would like to provide a simple
>>explanation of Perl objects, suitable for someone who hasn't met the
>>concept before?
>
> Perhaps I would, when I understand it.


Ben already has. (as he does understand it)


> For now about all I get is that
> the object is connected in some hidden way to the module it is "blessed"
> into, so that one of the subs in that module can be located and called
> when the object method call syntax is used. But that is guesswork,


But that is all you need to know in order to use objects.

You don't need to know how a car works in order to use a car.

If you want to know how objects are implemented or how a car works,
then "simple terms" are not what you are looking for.


> In my experience, with programming there is always a
> non-magic explanation, once you find it.


Yes, but then it won't be "simple".


> And yes, I would prefer "SV", "PVMG", and "SvSTASH"


Then you don't want it "in simple terms".


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
From: Ben Morrow on

Quoth "Newsgroup only please, address is no longer replyable." <bad(a)example.invalid>:
> On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
> <ben(a)morrow.me.uk> wrote,
> >
> >Quoth "Newsgroup only please, address is no longer replyable."
> <bad(a)example.invalid>:
> >> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
> >> <ben(a)morrow.me.uk> wrote,
> >> > In simple terms, an object is just a
> >> >refrence with a bit of magic attached.
> >>
> >> "bit of magic attached" isn't simple terms; it's pure obfuscation.
> >
> >If you say so. Would you rather I said 'an object is a reference to a
> >SV that is at least a PVMG, with SvSTASH set to point to the stash of
> >the class it's blessed into'?
>
> All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
> me as "magic".

Right. (I think perhaps your sarcasm detecter need recalibrating.)

> > Perhaps you would like to provide a simple
> >explanation of Perl objects, suitable for someone who hasn't met the
> >concept before?
>
> Perhaps I would, when I understand it. For now about all I get is that
> the object is connected in some hidden way to the module it is "blessed"
> into, so that one of the subs in that module can be located and called
> when the object method call syntax is used. But that is guesswork,
> coming mostly from what I think would have to happen for OOP to work,
> (and coming from C++) and not from anybody's explanation.

OK, that is pretty much right. You probably already know that every
(defined) scalar has a 'string' slot and a 'number' slot; every scalar,
array, hash, regex, sub, glob and IO also has a 'class' slot. When you
say

bless $ref, "Package";

perl dereferences $ref and sets the 'class' slot of whatever it
referenced to the symbol table of the package "Package". Later on, when
you call a method on $ref, perl starts its search for a method to use in
that package.

> And yes, I would prefer "SV", "PVMG", and "SvSTASH" as at least those
> suggest that searching for those keywords might eventually lead to the
> explanation, whereas "magic" surely will not.

Feel free to go through S_method_common in pp_hot.c in the perl
distribution until you understand what it's *actually* doing. I did, and
I learned a lot.

Ben

From: Justin C on
In article <5b1ev6-khd.ln1(a)osiris.mauzo.dyndns.org>, Ben Morrow wrote:
> OK, that is pretty much right. You probably already know that every
> (defined) scalar has a 'string' slot and a 'number' slot; every scalar,
> array, hash, regex, sub, glob and IO also has a 'class' slot. When you
> say
>
> bless $ref, "Package";
>
> perl dereferences $ref and sets the 'class' slot of whatever it
> referenced to the symbol table of the package "Package". Later on, when
> you call a method on $ref, perl starts its search for a method to use in
> that package.
>
> Feel free to go through S_method_common in pp_hot.c in the perl
> distribution until you understand what it's *actually* doing. I did, and
> I learned a lot.

I wish I'd stopped reading this thread sometime around Thursday! :)

Justin.

--
Justin C, by the sea.