Slide 1

Slide 1 text

Perl's Syntactic Legacy Using the future to improve the past

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

#eatfirst

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

$785.00!!!!

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

#dammitcancer

Slide 12

Slide 12 text

Perl's Syntactic Legacy Using the future to improve the past

Slide 13

Slide 13 text

Legacy /ˈlɛɡəsɪ/ ! adjective ! of or relating to old or outdated computer hardware, software, or data that, while still functional, does not work well with up-to-date systems.

Slide 14

Slide 14 text

/ˈlɛɡəsɪ/ ! noun ! something handed down or received from an ancestor or predecessor Legacy

Slide 15

Slide 15 text

/ˈlɛɡəsɪ/ ! noun ! something handed down or received from an ancestor or predecessor Legacy descendant or successor

Slide 16

Slide 16 text

This talk is about

Slide 17

Slide 17 text

This talk is about ‣ the evolution of a design

Slide 18

Slide 18 text

This talk is about ‣ the evolution of a design ‣ the slow breakdown of my own stubbornness

Slide 19

Slide 19 text

Learning

Slide 20

Slide 20 text

Learning The act of present $you realizing how stupid past $you was being

Slide 21

Slide 21 text

meta(data)

Slide 22

Slide 22 text

STEVAN [email protected] stevan @stevanlittle cpan: email: github: twitter:

Slide 23

Slide 23 text

1998

Slide 24

Slide 24 text

2002

Slide 25

Slide 25 text

2004

Slide 26

Slide 26 text

2005

Slide 27

Slide 27 text

2006

Slide 28

Slide 28 text

2011

Slide 29

Slide 29 text

mop?

Slide 30

Slide 30 text

Classes, Methods, Attributes & Instances

Slide 31

Slide 31 text

... an abstraction of a system of abstractions that is used to build abstractions.

Slide 32

Slide 32 text

... an abstraction of a system of abstractions that is used to build abstractions.

Slide 33

Slide 33 text

... an abstraction of a system of abstractions that is used to build abstractions.

Slide 34

Slide 34 text

... an abstraction of a system of abstractions that is used to build abstractions.

Slide 35

Slide 35 text

*{$pkg . '::foo'} = \&bar;

Slide 36

Slide 36 text

p5-mop

Slide 37

Slide 37 text

Goals

Slide 38

Slide 38 text

Goals 1. class attributes (slots)

Slide 39

Slide 39 text

Goals 1. class attributes (slots) 2. class/method vs. package/sub

Slide 40

Slide 40 text

Goals 1. class attributes (slots) 2. class/method vs. package/sub 3. role composition

Slide 41

Slide 41 text

Goals 1. class attributes (slots) 2. class/method vs. package/sub 3. role composition 4. introspection API

Slide 42

Slide 42 text

Goals 1. class attributes (slots) 2. class/method vs. package/sub 3. role composition 4. introspection API 5. improve OO syntax

Slide 43

Slide 43 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 44

Slide 44 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 45

Slide 45 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 46

Slide 46 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 47

Slide 47 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 48

Slide 48 text

package Point; ! sub new :method { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear :method { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 49

Slide 49 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 50

Slide 50 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 51

Slide 51 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 52

Slide 52 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 53

Slide 53 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 54

Slide 54 text

package Point; ! sub new { my $class = shift; bless { x => 0, y => 0 }, $class; } ! sub clear { my $self = shift; $self->{x} = 0; $self->{y} = 0; }

Slide 55

Slide 55 text

class Point { ! has $x = 0; has $y = 0; ! method clear { ($x, $y) = (0, 0); } }

Slide 56

Slide 56 text

Moose

Slide 57

Slide 57 text

Perl 5 Core Class::MOP Moose

Slide 58

Slide 58 text

Perl 5 Core Class::MOP Moose

Slide 59

Slide 59 text

p5-mop

Slide 60

Slide 60 text

Perl 5 Core mop.pm

Slide 61

Slide 61 text

Perl 5 Core mop.pm

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Throw the first one away!

Slide 67

Slide 67 text

PadWalker.pm

Slide 68

Slide 68 text

PadWalker.pm

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Who is going to maintain this?!!!?!?!

Slide 71

Slide 71 text

moe

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

-Ofun

Slide 74

Slide 74 text

ಠ_ಠ

Slide 75

Slide 75 text

My Moe Wishlist • A more consistent syntax and sane grammar • with a real AST • and better tooling support • A less insane runtime • proper MOP (everything is an object) • slimmer core • easy (non-XS) extension mechanism • On a modern VM platform • JVM / CLR / LLVM / V8 • cross language sharing

Slide 76

Slide 76 text

CPAN

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

p5-mop-redux

Slide 85

Slide 85 text

Perl 5 Core mop.pm

Slide 86

Slide 86 text

Perl 5 Core mop.pm

Slide 87

Slide 87 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 88

Slide 88 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 89

Slide 89 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 90

Slide 90 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 91

Slide 91 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 92

Slide 92 text

package Foo; use strict; use warnings; ! use Variable::Magic qw[ wizard cast ]; use Hash::Util::FieldHash qw[ fieldhash ]; ! fieldhash my %foo; ! my $wiz = wizard( data => sub { $_[1] }, set => sub { $_[1]->[0]->{ $_[1]->[1] } = $_[0] }, ); ! sub foo { my $self = shift; my $foo = $foo{$self}; cast $foo, $wiz, [ \%foo, $self ]; ! $foo = shift if @_; $foo; }

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

package Foo; use strict; use warnings; ! has ‘foo’; ! method foo { $foo = shift if @_; $foo; }

Slide 95

Slide 95 text

Devel::(every day i’m segfaultin)::Declare

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

Everything should be as simple as it can be, but not simpler. – Albert Einstein

Slide 98

Slide 98 text

It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience.

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

• Plack

Slide 101

Slide 101 text

• Plack • HTTP::Headers::ActionPack

Slide 102

Slide 102 text

• Plack • HTTP::Headers::ActionPack • Promises

Slide 103

Slide 103 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board

Slide 104

Slide 104 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board • Reply

Slide 105

Slide 105 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board • Reply • Forward::Routes

Slide 106

Slide 106 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board • Reply • Forward::Routes • Action::Retry

Slide 107

Slide 107 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board • Reply • Forward::Routes • Action::Retry • Hashids

Slide 108

Slide 108 text

• Plack • HTTP::Headers::ActionPack • Promises • Bread::Board • Reply • Forward::Routes • Action::Retry • Hashids • Net::IPAddress::Util

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

200 OK

Slide 111

Slide 111 text

Perl 5 Core mop.pm

Slide 112

Slide 112 text

Perl 5 Core mop.pm

Slide 113

Slide 113 text

Perl 5 Core mop.pm

Slide 114

Slide 114 text

Perl 5 Core mop.pm

Slide 115

Slide 115 text

Perl 5 Core mop.pm XS

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

p5-mop-XS

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

Perl 5 Core

Slide 121

Slide 121 text

mop.xs Perl 5 Core

Slide 122

Slide 122 text

p5-mop-again-seriously-wtf

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

sub foo; # required method

Slide 126

Slide 126 text

$ perl -MDevel::Peek -e 'sub foo; Dump \&foo;' SV = IV(0x7fa3b3003428) at 0x7fa3b3003438 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x7fa3b3028978 SV = PVCV(0x7fa3b30271b8) at 0x7fa3b3028978 REFCNT = 2 FLAGS = () COMP_STASH = 0x7fa3b30032b8 "main" ROOT = 0x0 GVGV::GV = 0x7fa3b3028960 "main" :: "foo" FILE = "-e" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 0 PADLIST = 0x0 OUTSIDE = 0x0 (null)

Slide 127

Slide 127 text

# marking sub as method sub foo :method { … }

Slide 128

Slide 128 text

perl -MDevel::Peek -e 'sub foo :method { 1 } Dump \&foo;' SV = IV(0x7fec82003428) at 0x7fec82003438 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x7fec82029318 SV = PVCV(0x7fec82027bb8) at 0x7fec82029318 REFCNT = 2 FLAGS = (METHOD) COMP_STASH = 0x7fec820032b8 "main" START = 0x7fec81c0dae8 ===> 1 ROOT = 0x7fec81c0da60 GVGV::GV = 0x7fec82029348 "main" :: "foo" FILE = "-e" DEPTH = 0 FLAGS = 0x1 OUTSIDE_SEQ = 95 PADLIST = 0x7fec81c0cac0 PADNAME = 0x7fec82029378(0x7fec81c0cf90) PAD = 0x7fec820293c0(0x7fec81c051e0) OUTSIDE = 0x7fec82003648 (MAIN)

Slide 129

Slide 129 text

# signatures sub foo ($self) { … }

Slide 130

Slide 130 text

+ use v5.20; + use experimental ‘signatures’ + - SV* - parse_signature (code, …) - # A WHOLE LOAD OF CRAZY XS - # PARSING CODE THAT MADE YOUR - # EYES BLEED AND YOUR HEART - # SINK IN DEEP DESPAIR - # *sigh*

Slide 131

Slide 131 text

sub foo; ! sub bar :method { … } ! sub baz ($gorch) { … }

Slide 132

Slide 132 text

package Foo; use v5.20; use warnings; ! our @DOES = (‘BarRole’); ! 1;

Slide 133

Slide 133 text

package Foo; use v5.20; use warnings; ! our %HAS = ( bar => sub { “BAR” }, baz => sub { “BAZ” }, ); ! 1;

Slide 134

Slide 134 text

our @DOES = (‘BarRole’); ! our %HAS = ( bar => sub { “BAR” }, baz => sub { “BAZ” }, );

Slide 135

Slide 135 text

#include “mop.h”

Slide 136

Slide 136 text

p5-mop

Slide 137

Slide 137 text

Conclusion

Slide 138

Slide 138 text

Respect the Legacy!

Slide 139

Slide 139 text

Legacy is the remnants of solved problems.

Slide 140

Slide 140 text

Many of the OO conventions that we take for granted are largely inherited from Java, ! … which barely existed when Larry designed the OO features of Perl 5.

Slide 141

Slide 141 text

Object Orientation in Ada is a Design Pattern

Slide 142

Slide 142 text

What makes a good “Perl” programmer? • Laziness • Impatience • Hubris

Slide 143

Slide 143 text

What makes a good “perl” programmer? • Do the hard work • Patience • Humility

Slide 144

Slide 144 text

The End (or is it…)