Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

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/
  3. Dedication David Adler Jeff Goff 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/ Sparky
  4. What is Corinna? https://github.com/Ovid/Cor (This talk is not a tutorial on Corinna) 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  5. The Lisp Curse 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/
  7. Perl Core OOP (Today) • bless • @ISA 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/
  16. 80+ OOP systems on the CPAN Mo Mu Mic Moo Mew Dios Moose Moops Moxie reform Spiffy Zydeco HO::Class Class::LOP Evo::Class Class::Dot Class::Ref Class::Std Mojo::Base Eixo::Base Class::Root Class::Easy Class::Core Class::Base Class::Lite Class::Lego Class::GAPI Class::Slot Class::Tiny Class::Gomor Class::Field Rose::Object Class::Maker Class::HPLOO Class::Frame Class::Class Class::Simple Class::Attrib Class::Closure Class::Methods Class::Builder Class::Declare Class::Accessor Class::Contract Class::Generate Class::InsideOut Acme::Class::Std Class::Anonymous Class::Classless Class::Std::Fast Class::Framework Class::Autoclass Class::Methodist Bubblegum::Class Object::LocalVars Object::InsideOut Class::AutoAccess Class::Prototyped Class::Structured Class::NamedParms Class::Constructor AI::FreeHAL::Class Class::BuildMethods Lexical::Attributes Class::AccessorMaker Class::IntrospectionMe thods Class::MakeMethods::Te mplate::InsideOut 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  17. Dios Damian Conway class Identity is Trackable { shared Num %!allocated_IDs; shared Num $.prev_ID is rw; func _allocate_ID() { while (1) { lex Num $ID = rand; return $prev_ID =$ID if !$allocated_IDs{$ID}++; } } has Num $.ID = _allocate_ID(); has Str $.name //= '<anonymous>'; has Passwd $!passwd; method identify (Str $pwd --> Str) { return "$name [$ID]" if $pwd eq $passwd; } submethod DESTROY { say "Bye, $name!"; } } 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  18. Zydeco Toby Inkster class Person { has name ( type => Str, required => true ); has gender ( type => Str ); factory new_man (Str $name) { return $class->new(name => $name, gender => 'male'); } factory new_woman (Str $name) { return $class->new(name => $name, gender => 'female'); } method greet (Person *friend, Str *greeting = "Hello") { printf("%s, %s!n", $arg->greeting, $arg->friend->name); } coerce from Str via from_string { return $class->new(name => $_); } } 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  19. Why do they stand out? They didn’t limit themselves to what Perl can do today 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  20. 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 }; field $created :reader { time }; 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/
  21. How Did We Get Here? 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  22. Ovid’s Sponsor • All Around the World • https://allaroundtheworld.fr/ 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  23. Paul Evans’ Sponsors Sponsor Amount Oetiker+Partner AG 1000 CFH Perl-Verein Schweiz 3000 CHF Deriv Ongoing Anonymous … 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/
  38. 3. Same ideas, different syntax 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/
  51. Methods are not subs This might not make to the 1st version. 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/
  53. Corinna is Simple! Copyright 2022, http://www.allaroundtheworld.fr/ March 30, 2022
  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
  64. Questions? 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  65. TYPES? Copyright 2022, http://www.allaroundtheworld.fr/ March 30, 2022
  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
  69. NO TYPES 😢 Copyright 2022, http://www.allaroundtheworld.fr/ March 30, 2022
  70. But … Copyright 2022, http://www.allaroundtheworld.fr/ 30 mars 2022
  71. IMMUTABLE OBJECTS Copyright 2022, http://www.allaroundtheworld.fr/ March 30, 2022
  72. 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/
  73. Type Library package Our::Types { use Less::Boilerplate; use Type::Library -base; use Type::Utils -all; use Type::Params; our @EXPORT_OK; BEGIN { extends qw( Types::Standard Types::Common::Numeric Types::Common::String ); push @EXPORT_OK => qw/compile compile_named/; } } 1; 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/
  74. Corinna + Types class Name { use Our::Types qw(NonEmptyStr Maybe compile); field $name :param; field $title :param { undef }; ADJUST { state $check = compile(NonEmptyStr,Maybe[NonEmptyStr]); $check->( $name, $title ); } method name () { return $title ? "$title $name" : $name; } } 30 mars 2022 Copyright 2022, http://www.allaroundtheworld.fr/

Editor's Notes

  1. Apologies, I must leave tomorrow (scheduling conflict)
  2. Confession: my first versions of Corinna had the same flaw.
  3. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  4. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  5. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  6. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  7. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  8. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  9. Offers modern OO facilites *and* is uses UNIVERSAL::Object for newer OO frameworks to be built on top of it!
  10. Instead of my coding limitations, I would be limited by my imagination
  11. Same ideas, different syntax: not offering anything new
  12. These are many positive side-effects emerging from one simple design change.
  13. These are many positive side-effects emerging from one simple design change.
  14. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
  15. Most OOP systems in Perl are built on top of this. No built-in notion of state or encapsulation,
Advertisement