The current status of the Corinna OOP proposal for the Perl programming language.
After years of design and discussion, the Perl Steering Committee has accepted the Corinna RFC (in a scaled-back initial form) for inclusion in the Perl language.
This talk gives the history of the proposal and where we're going from here.
Boost PC performance: How more available memory can improve productivity
Corinna Status 2022.pptx
1. Corinna Status
Update
Modern OOP is coming to Perl
Curtis “Ovid” Poe
https://allaroundtheworld.fr/
https://ovid.github.io/
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
2. Question Policy
• Please hold them to the end
• Unless something is completely incomprehensible
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
6. The Lisp
Perl Curse
(edited)
Since making Perl object systems is not
hard, many Perl hackers have done so.
More to the point, many individual Perl
hackers have done so. Programs written
by individual hackers tend to follow the
scratch-an-itch model. These programs
will solve the problem that the hacker is
having without necessarily making the
software more useful to others. This
means that these one-man-band
projects tend to solve eighty-percent of
the problem.
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
8. Perl Core
OOP
(Today)
• bless–We have methods!
• @ISA–Where are the methods?
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
9. Perl Core
OOP
(Today)
• bless–We have methods subroutines!
• @ISA–Where are the methods subroutines?
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
10. Perl Core
OOP
(Today)
package Name;
sub new {
my ( $class, %arg_for ) = @_;
return bless {
name => $arg_for{name},
title => $arg_for{title},
}, $class;
}
sub _title { $_[0]->{tilte} }
sub _name { $_[0]->{name} }
sub name {
my $self = shift;
my $title = $self->_title;
my $name = $self->_name;
return $title ? "$title $name"
: $name;
}
1;
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
11. Perl Core
OOP
(Today)
my $ovid = Name->new( name => 'Ovid' );
my $doctor = Name->new(
title => 'Dr.',
name => 'Who',
);
say $ovid->name; # Ovid
say $doctor->name; # Dr. Who
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
12. Perl Core
OOP
(Today)
package Name;
sub new {
my ( $class, %arg_for ) = @_;
return bless {
name => $arg_for{name},
title => $arg_for{title},
}, $class;
}
sub _title { $_[0]->{tilte} }
sub _name { $_[0]->{name} }
sub name {
my $self = shift;
my $title = $self->_title;
my $name = $self->_name;
return $title ? "$title $name"
: $name;
}
1;
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
13. Corinna
class Name {
field $name :param;
field $title :param { undef };
method name () {
return $title ? "$title $name" : $name;
}
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
14. Perl Core
OOPS
package Name;
sub new {
my ( $class, %arg_for ) = @_;
return bless {
name => $arg_for{name},
title => $arg_for{title},
}, $class;
}
sub _title { $_[0]->{tilte} }
sub _name { $_[0]->{name} }
sub name {
my $self = shift;
my $title = $self->_title;
my $name = $self->_name;
return $title ? "$title $name"
: $name;
}
1;
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
15. Corinna
class Name {
field $name :param;
field $title :param { undef };
method name () {
return $Title ? "$tilte $name" : $name;
}
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
24. Corinna Team/Influencers/Contributors
(Incomplete list by first name)
• Curtis “Ovid” Poe
• Damian Conway
• Dan Book (Grinnz)
• Graham Knop (haarg)
• Harald Jörg
• Matt Trout
• Paul Evans
• Sawyer X
• Stevan Little
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
25. History
• March 2006: Stevan Little releases Moose 0.1
• March 2010: Stevan Little releases Moose 1.0
• June 2017: Stevan releases Moxie
• June 2019: Ovid starts working on Corinna (née Cor)
• August 2019: Riga Perl Conference. Sawyer X blows my mind
• October 2019: First public announcement of Corinna
• October 2019: Paul Evans starts work on Object::Pad test bed
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
26. Moxie
package Point {
use Moxie;
extends 'Moxie::Object';
has x => ( default => sub { 0 } );
has y => ( default => sub { 0 } );
sub x : ro;
sub y : ro;
sub clear ($self) {
$self->@{ 'x', 'y' } = (0, 0);
}
}
30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
27. Corinna
class Point {
field ( $x, $y ) :param :reader {0};
method clear () { $x = 0; $y = 0; }
}
30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
28. Pre-History
• Based on Keyword::Declare
• Implementation + Test Suite
• Influenced by Moxie ideals
• Heavily reflected Moose heritage
• Lost when a pipe burst in our house
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
29. Sawyer X Arrives
• 2019 Riga Perl Conference
• Sawyer X tells me to ditch the implementation
• “Design something great.”
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
30. Early
Work
Ovid
class Cache::LRU {
use Hash::Ordered;
has cache => (default => sub { Hash::Ordered->new });
has max_size => (default => sub { 20 });
method set ( $key, $value ) {
if ( self->cache->exists($key) ) {
self->cache->delete($key);
}
elsif ( self->cache->keys > self->max_size ) {
self->cache->shift;
}
self->cache->set( $key, $value );
}
method get ($key) {
if ( self->cache->exists($key) ) {
my $value = self->cache->get($key);
self->set( $key, $value ); # add to front
return $value;
}
return;
}
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
31. Features
• Cleaner syntax
• self as a keyword
• Methods and subroutines are no longer the same thing
• Encapsulation by default (but my design was bad)
• No declarative way to expose state (another design flaw)
• Lexical variables for state were considered (but I considered them
“unperlish”)
• Paul “LeoNerd” Evans argued for lexical variables for state (he was
right)
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
32. Corinna
The Corinna
Team
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
method set ( $key, $value ) {
if ( $cache->exists($key) ) {
$cache->delete($key);
}
elsif ( $cache->keys > $max_size ) {
$cache->shift;
}
$cache->set( $key, $value ); # add to front
}
method get ($key) {
if ( $cache>exists($key) ) {
my $value = $cache->get($key);
$self->set( $key, $value ); # add to front
return $value;
}
return;
}
} 30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
33. Moose
Damnit,
Stevan
package Cache::LRU {
use Moose;
use Hash::Ordered;
use namespace::autoclean;
has '_cache' => (
is => 'ro',
init_arg => undef,
default => sub { Hash::Ordered->new },
);
has 'max_size' => ( is => 'ro', default => 20 );
sub set {
my ( $self, $key, $value ) = @_;
if ( $self->_cache->exists($key) ) {
$self->_cache->delete($key);
}
elsif ( $self->_cache->keys >= $self->max_size ) {
$self->_cache->shift;
}
$self->_cache->set( $key, $value );
}
sub get {
my ( $self, $key ) = @_;
$self->_cache->get($key)
if ( $self->_cache>exists($key) ) {
my $value = $self->_cache->get($key);
$self->set( $key, $value ); # add to front
return $value;
}
}
__PACKAGE__->meta->make_immutable;
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
34. Objections
1. bless is good enough for me
2. Moo/se won. It should be in core
3. Same ideas, different syntax
4. How can I debug encapsulated objects?
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
35. 1. bless is good enough for
me
• We’re not removing bless.
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
36. 2. Moo/se won. It should be in
core
• A popular minority view
• They're great, mature modules, but …
• The authors, Stevan Little (Moose) and Matt Trout (Moo) aren’t arguing
for this
• P5P doesn’t want them
• They’re hobbled by the current limitations of Perl
See also: https://ovid.github.io/articles/why-is-perl-not-putting-
moose-in-the-core.html
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
37. Current Limitations of Perl
• Methods are subroutines
• Classes are packages
• No native state
• No native encapsulation
• No native delegation
• No differentiation between class methods and instance methods
• Classes are not “first-class” types
• … and on and on and on
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
39. 3. Same
ideas,
different
syntax
• We’ve been explaining the difference for years
• It’s hard to keep explaining, so you point them to
the RFC
• But this is really important, so here goes…
30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
40. Background
• Based on decades of personal OOP experience
• Supported by Stevan Little (creator of Moose)
• Supported by Matt Trout (creator of Moo)
• Supported by Damian Conway (designer of Raku and SPEC OOP
systems)
• Ideas from far too many books, papers, and articles on OOP and
type systems
• Designed to create a “Perlish” OOP system
• Subject to two DMCA takedown notices from an OnlyFans “artist” 30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
41. 237th time’s the
charm!
3. Same ideas, different syntax
Copyright 2022, http://www.allaroundtheworld.fr/ March 30, 2022
42. Chris “Peregrin” Prather to P5P
• Class composition: “Design Patterns: Elements of Reusable Object-
Oriented Software”, published literally 4 days after Perl 5.000 says
to prefer composition to inheritance.
• Perl’s only native solution to reusable behavior is inheritance.
• Perl has no native solution to encapsulation (there are complex
workarounds)
Source: https://markmail.org/message/pxmkevqe7qg7tld2, June
19, 2021
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
43. Native
composition
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
method set ( $key, $value ) {
if ( $cache->exists($key) ) {
$cache->delete($key);
}
elsif ( $cache->keys > $max_size ) {
$cache->shift;
}
$cache->set( $key, $value );
}
…
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
44. Native state
and
composition
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
method set ( $key, $value ) {
if ( $cache->exists($key) ) {
$cache->delete($key);
}
elsif ( $cache->keys > $max_size ) {
$cache->shift;
}
$cache->set( $key, $value );
}
…
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
45. Native state,
encapsulation
, and
composition
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
method set ( $key, $value ) {
if ( $cache->exists($key) ) {
$cache->delete($key);
}
elsif ( $cache->keys > $max_size ) {
$cache->shift;
}
$cache->set( $key, $value );
}
…
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
46. Runtime
failures
package Cache::LRU {
use Moose;
use Hash::Ordered;
has '_cache' => (
is => 'ro',
init_arg => undef,
default => sub {Hash::Ordered->new},
);
has 'max_size' => (
is => 'ro',
default => 20,
);
sub set ( $self, $key, $value ) {
if ($self->_cahce->exists($key)) {
$self->_cache->delete($key);
}
…
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
47. Become
Compile-time
failures
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
method set ( $key, $value ) {
if ( $cach->exists($key) ) {
$cache->delete($key);
}
elsif ( $cache->keys > $max_size ) {
$cache->shift;
}
$cache->set( $key, $value );
}
…
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
48. Fields no
longer
exposed
by
default.
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
…
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
49. init_arg
=> undef
no longer
needed
class Cache::LRU :version(v0.1.0) {
use Hash::Ordered;
field $cache { Hash::Ordered->new };
field $max_size :param :reader { 20 };
…
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
50. Methods
are not
subs
class Some::Class :version(v0.1.0) {
use Some::Module 'set';
method set ( $key, $value ) {
if ( set( … ) ) {
# subroutine called, not the method
}
…
}
…
}
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
52. 4. Debugging encapsulated
objects
• The MOP will allow encapsulation violation
• It will be harder to do
• Violating encapsulation becomes the last choice, not the first
• Data::Printer, Data::Dumper, the debugger, and other tools
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
54. Four Little Words
• class
• role
• field
• method
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
55. blogs.perl.org
• A dream realized
• A dream resyntaxed
• A (not so) simple matter of privacy
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
56. use feature "class";
• perldoc -f class
• perldoc -f role
• perldoc -f field
• perldoc -f method
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
57. Modifiers
• class My::Class :isa(Other::Class)
• role My::Role :does(Other::Role)
• field $name :param :reader
• method frobnicate :common
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
58. January 16, 2022
Corinna RFC Accepted
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
59. Accepted with Caveats
• Corinna was not completely accepted
• Smaller, easier to test features, one at a time
• A Minimally Minimum Viable Product (MMVP)
Copyright 2022, http://www.allaroundtheworld.fr/ 30 mars 2022
60. Who?
• Paul Evans—LeoNerd
• Object::Pad
• Future::AsyncAwait
• Syntax::Keyword::Try
• Much more
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
61. The MMVP Steps
1. Classes
2. Inheritance
3. Roles
4. Field modifiers
5. Field initializer blocks
6. Meta-Object Protocol (MOP)
7. Method modifiers
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
62. Perl Steering Council Meeting 2022-03-11
“Paul let us know that he’s now got a sponsor to cover his
initial Corinna implementation work, and his plan is to
land the first stage at the start of the 5.37 dev cycle.”
https://www.nntp.perl.org/group/perl.perl5.porters/2022/03/msg263374.html
30 mars 2022
Copyright 2022, http://www.allaroundtheworld.fr/
63. Timefram
e
30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
None
Almost three years of design
(based on years of prototypes)
Make it right, not make it now
66. Corinna +
Types!
• Early work had types
• Everybody wants them
• All of the designers said “no”
30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
67. The Problem
with Types
• Variable declarations
• Field declarations
• Subroutine arguments
• Method arguments
• Casting
• … and more ???
Copyright 2022, http://www.allaroundtheworld.fr/ 30 mars 2022
68. The Problem
with Types
• Built-in Types?
• Int, Float, Char, etc.
• User-defined Types?
• Classes
• Subtypes
Copyright 2022, http://www.allaroundtheworld.fr/ 30 mars 2022