Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl 5: Postcards from the Edge

Perl 5: Postcards from the Edge

Ricardo Signes

June 05, 2013
Tweet

More Decks by Ricardo Signes

Other Decks in Programming

Transcript

  1. We love our perl. It is a mess. Nobody is

    going to change that. So don't worry.
  2. What is new? Why is it new? What will be

    new next? What won't? Why?
  3. - Renaming packages through glob assignment ("*Foo:: = *Bar::; *Bar::

    = *Baz::") in combination with "m?...?" and "reset" no longer makes threaded builds crash.
  4. Regex Sets - regex have character sets: - $a =~

    /[a-z]/ - but you can't do set operations
  5. Regex Sets - regex have character sets: - $a =~

    /[a-z]/ - but you can't do set operations - …except for addition
  6. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} )

    & ( ! \p{Script=Cyrillic}) Regex Sets
  7. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} )

    & ( ! \p{Script=Cyrillic}) ])/ Regex Sets
  8. no warnings 'experimental::regex_sets'; $a =~ /(?[ ( \pL + \pN

    - \p{Numeric_Value=3} ) & ( ! \p{Script=Cyrillic}) ])/ Regex Sets
  9. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y
  10. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y }
  11. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ );
  12. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); }
  13. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2);
  14. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3);
  15. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4);
  16. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3
  17. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 # 5
  18. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 # 5 # 7
  19. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4);
  20. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !?
  21. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !? # 4 !?
  22. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !? # 4 !? # 5 !?
  23. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”);
  24. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); }
  25. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } }
  26. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper {
  27. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines {
  28. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”);
  29. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); }
  30. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  31. # ...some test file... my sub diag { say $_[0];

    emit_diagnostics; } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  32. Some bad thing happened at file.p5 line 12. main::emit_diagnostics(...) called

    at file.p5 line 10 (unknown)(3, 4) called at file.p5 line 9 Tester::test_xyz() called at file.p5 line 15
  33. # ...some test file... our sub diag { say $_[0];

    emit_diagnostics; } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  34. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); }
  35. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y
  36. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y }
  37. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y } adder( @_ );
  38. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y } adder( @_ ); }
  39. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y }
  40. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y } adder( @_ );
  41. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y } adder( @_ ); }
  42. sub print_next { my $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; } sub reset_stdout { ... } sub reset_stdout(_) { ... }
  43. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch { die $_ unless /ignore/; }
  44. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch sub (_) { die $_[0] unless $_[0] =~ /ignore/; }
  45. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch { die $::_ unless $::_ =~ /ignore/; }
  46. $a $b Meaning ======= ======= =============== Any undef ! defined

    $a Any ~~-overloaded ~~ overloading Any Regexp, qr-ol $a =~ $b Any CodeRef, &{}-ol $b->($a) Any Any fatal
  47. $a $b Meaning ======= ======= =============== Any undef ! defined

    $a Any ~~-overloaded ~~ overloading Any Regexp, qr-ol $a =~ $b Any CodeRef, &{}-ol $b->($a) Any Any fatal given ($x) { when ($y) { ... } # $x ~~ $y when (4) { ... } # $x == 4 when (‘4’) { ... } # $x eq 4 }
  48. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ };
  49. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ }; }
  50. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ }; } }
  51. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); "Common" Knowledge
  52. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; "Common" Knowledge
  53. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 "Common" Knowledge
  54. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END "Common" Knowledge
  55. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END 1234 "Common" Knowledge
  56. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END 1234 1234 "Common" Knowledge
  57. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); "Common" Knowledge
  58. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; "Common" Knowledge
  59. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 "Common" Knowledge
  60. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END "Common" Knowledge
  61. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 "Common" Knowledge
  62. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 112334 "Common" Knowledge
  63. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 "Common" Knowledge
  64. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 112334 "Common" Knowledge
  65. Just Remember… - keys %hash and values %hash are in

    the same order as each other - they both change if you alter the hash - so does each and list order
  66. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y
  67. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y # ('␠') x 3,
  68. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y # ('␠') x 3, # z
  69. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it
  70. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it - see how much you broke, how much you win
  71. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it - see how much you broke, how much you win - and then I can steal your work from you
  72. Τί ἐστιν Περλ; - "Perl should get more Perlish." -

    What? - Perl is a whole made of parts that work together nicely.
  73. Τί ἐστιν Περλ; - "Perl should get more Perlish." -

    What? - Perl is a whole made of parts that work together nicely. - (pause for laughter)
  74. Backcompat Killed My Dog - "We should break horrible old

    features to allow evolution." - "We don't make change because of backcompat."
  75. - "We all agree on the necessity of compromise. We

    just can't agree on when it's necessary to compromise." — Larry Backcompat Killed My Dog
  76. - "We all agree on [removing cruft]. We just can't

    agree on [what cruft] to [remove]." — [Larry] Backcompat Killed My Dog
  77. Talked To Death - maybe we figure out that it

    was a bad idea - maybe the perfect is the enemy of the good
  78. Talked To Death - maybe we figure out that it

    was a bad idea - maybe the perfect is the enemy of the good - maybe nobody's willing to decide the debate
  79. <Phaedo> how to deprecate: step 1. have a huge flame-war

    on p5p mailing list <Alcibiades> step 2. after no conclusive result on the mailing list, deprecate anyway
  80. - "We all agree on the necessity of compromise. We

    just can't agree on when it's necessary to compromise." — Larry Talked to Death
  81. - "We all agree on the necessity of compromise. [Ricardo

    can] agree on when it's necessary to compromise." — [Ricardo] Talked to Death
  82. - most of our patches come from four people -

    Perl is not dead - but perl5.git is on life support - but: everybody in this room is a doctor
  83. - If you want a feature… - …write it! -

    If you don't know how… - ask for help.
  84. - If you want a feature… - …write it! -

    If you don't know how… - ask for help. - If you don't want to write it…
  85. - If you want a feature… - …write it! -

    If you don't know how… - ask for help. - If you don't want to write it… - discuss with p5p how it might help.
  86. { use autodie; open my $fh, ‘>’, $filename; $fh->print( ...

    ); } # should die if close fails! fatal implicit close()
  87. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y; push

    $x->{foo}->[0]->m->@*, $y; push @y, @{ $x->{foo}->[0]->m };
  88. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y; push

    $x->{foo}->[0]->m->@*, $y; push @y, @{ $x->{foo}->[0]->m }; push @y, $x->{foo}->[0]->m->@*;
  89. my $x = try { $y / $z } catch

    { return $Infinity if $_->tagged(‘divbyzero’); die $_; } better exceptions
  90. my $buf = $fh->readline; my $str = decode_utf8($buf); STDOUT->print( $str

    ); # fatal unless encoding layer chars v. bytes