Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: OO systems and Perl 5 (Was: Recap: Future of Perl 5)

by RonW (Parson)
on Aug 31, 2018 at 00:04 UTC ( #1221412=note: print w/replies, xml ) Need Help??


in reply to Re^3: OO systems and Perl 5 (Was: Recap: Future of Perl 5)
in thread OO systems and Perl 5 (Was: Recap: Future of Perl 5)

Semantically, you are right.

But, that is not the issue Ovid raised in Recap: The Future of Perl 5.

In his proposal, Ovid seeks to reduce the number of required steps and simplify the syntax in Perl 5's OO system.

As to why I said Python's OO system seems to have changed since Larry stole from it, see the Python 3 example:

class Dog: # Class Attribute species = 'mammal' # Initializer / Instance Attributes def __init__(self, name, age): self.name = name self.age = age # Instantiate the Dog object philo = Dog("Philo", 5)

__init__ is called with an already "blessed" ref to an already allocated container. __init__ only sets values to the objects's fields.

The 1-to-1 translation to Perl would be (using signatures to reduce "noise"):

package Dog; our $species = 'mammal'; sub __init__ ($class, $name, $age) { my $self = {}; $self->{name} = $name; $self->{age} = $age; bless $self, $class; } package main; my $philo = Dog->__init__('Philo', 5);

Even if we make __init__ more Perl-ish (still using signatures):

sub __init__ ($class, $name, $age) { my $self = bless {name => $name, age => $age}, $class; }

Ovid would still point out that Perl is requiring the programmer to perform 2 extra steps: Allocate the container and create a blessed reference to the container.

I don't know which version of Python Larry stole the OO system from, so I don't know what Larry changed. But, at least to me, Perl 5's classes look more like Smalltalk classes than Python 3 classes.

Replies are listed 'Best First'.
Re^5: OO systems and Perl 5 (updated)
by LanX (Archbishop) on Aug 31, 2018 at 01:15 UTC
    There are many object models out there, or used to be.

    Semantics count and the will to blend it into Perl 4.

    NB: Python has no packages.

    I already explained my interpretation of compromises he did for more flexibility.

    edit

    BUT I have to admit that I struggled a lot with Perlootut before reading Damian's book....

    There is a saying that emacs is not an IDE but an IDE construction set.

    The same seems to apply to Perl and OOP.

    You can mimic most of the syntactic sugar of Python, though I'd rather try copying Ruby.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      You can mimic most of the syntactic sugar of Python, though I'd rather try copying Ruby.

      I only discussed Python OO because someone mentioned that Larry said he stole Python's OO system (and then repented).

      When I was doing my searching, among the OO systems I found, Smalltalk was closest to Perl 5's OO system.

      (As for Ruby, maybe Python 3 stole Ruby's OO system.)

        > As for Ruby, maybe Python 3 stole Ruby's OO system.)

        This would surprise me. Any details?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1221412]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2019-04-23 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (115 votes). Check out past polls.

    Notices?