Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by LanX (Archbishop)
on Aug 29, 2018 at 00:57 UTC ( #1221284=note: print w/replies, xml ) Need Help??


in reply to OO systems and Perl 5 (Was: Recap: Future of Perl 5)

> Not sure what else Larry et al had available to look at,

IIRC was it Python, and he said he repented it.

edit

Larry Wall's 11th State of The Onion:

I don't really know much about Python. I only stole its object system for Perl 5. I have since repented.

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

  • Comment on Re: OO systems and Perl 5 (Was: Recap: Future of Perl 5)

Replies are listed 'Best First'.
Re^2: OO systems and Perl 5 (Was: Recap: Future of Perl 5)
by eyepopslikeamosquito (Chancellor) on Aug 29, 2018 at 04:35 UTC

    Yeah, this was discussed recently by you and I in a reply (Re^7: Curious about Perl's strengths in 2018) to the original discussion posted by Crosis. There were a lot of interesting topics discussed in this long (and at times meandering) discussion thread.

Re^2: OO systems and Perl 5 (Was: Recap: Future of Perl 5)
by RonW (Parson) on Aug 29, 2018 at 23:09 UTC
      What exactly? ? ?

      update

      I read all of it and this is semantically almost identical.

      Larry just reused package for class and added more freedom:

      • you can choose the name of your constructor(s) (usuall new)
      • you can bless any reference as instance container not only hashes
      • you won't have collisions between methods and instance vars
      • class attributes don't collide with object attributes

      Actually you can translate this whole tutorial almost 1-to-1 with a bit of syntactic sugar!

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

      ) python doesn't seem to have anything like a package keyword

        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2019-05-23 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (146 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!