4 ms·
Um, perhaps I'm misunderstanding your point, but Perl 5's object model was based on that of Python. And every method of a Perl 5 object receives a $self scalar
by nocman 7y ago
Um, perhaps I'm misunderstanding your point, but Perl 5's object model was based on that of Python.
And every method of a Perl 5 object receives a $self scalar as its first argument ( see https://perldoc.perl.org/perlobj.html https://perldoc.perl.org/perlobj.html ).
In fact, Larry Wall specifically stated in the 11th "State of the Onion" speech that he "stole" Python's object system for Perl 5.
I remembered him saying this, so I went to find the transcript. However, I could not find a transcript of the actual speech. I did, though, find this perlmonks.org quote of Larry Wall (from that speech):
"I don't really know much about Python. I only stole its object system for Perl 5. I have since repented."
https://www.perlmonks.org/?node_id=1212836 https://www.perlmonks.org/?node_id=1212836
So unless you mean Perl 5's "$self" is somehow "non-magic" (whatever you mean by that), I guess I don't understand what you mean when you say it has no "this" or "self".
- tyingq 7y agoIt doesn't have $this or $self. It has @_, which predates the OO that went into Perl.
- nocman 7y agoSorry, just getting back to this. Yeah, it has @_, and in the Perl object model, the first entry in the @_ array is a reference to the object, which is almost always called $self. Anyway, what people name the reference doesn't matter. The point is that it functions like 'this' and 'self' do in other languages, and it is very much required in object methods (which differ from normal subs in that they are passed that first argument automatically).