Low-Maintenance Perl

721 views

Published on

This talk was presented at OSCON 2006 and ApacheCon 2006. It suffers quite a bit from not having the commentary that went with the slides, but my notes for this talk are available on this site as a PDF.

This talk was probably the most well-received OSCON talk I've ever done. There were a lot of jokes and people were rolling in the aisles. Larry Wall and Damian Conway attended the talk at OSCON and while they did argue a couple of points they mostly laughed along.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
721
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Low-Maintenance Perl

  1. 1. low maintenance perl “optimizing for an easy life” perrin harkins plus three
  2. 2. the fud“i would never use perl for a large project.”“perl is unmaintainable.”“perl is write­only.”
  3. 3. i shouldnt have to tell you thisuse strict;use warnings;perltidy
  4. 4. know your audience“code is always read more times than it is  written.” andy hunt
  5. 5. choosing a dialectdont use something complex when  something simple will work.
  6. 6. choosing a dialectdont do things in a magical way when an  explicit way will work.
  7. 7. choosing a dialectdont make your code complex just so you  can get a certain syntax.
  8. 8. choosing a dialectfetch("search.cpan.org") > my @cont; is equivalent tomy $scraper = FEAR::API­>fear();my $page = $scraper­>fetch("search.cpan.org");push my @cont, $page­>document­>as_string;
  9. 9. choosing a dialectfollow conventions when you can.
  10. 10. choosing a dialect which scans faster?s{foo}{bar}g;s/foo/bar/g;
  11. 11. choosing a dialectdont use an obscure language feature  when a common one will work.
  12. 12. choosing a dialect dragonchilds law:"if i have to ask if something is possible on  perlmonks, i probably should rethink my  design."
  13. 13. obscure features “We redesigned the protocol several times until we had a  protocol that performed well. However, the resulting protocol was too complex and depended on the  behavior of Chubby features that were seldom exercised by  other applications. We discovered that we were spending an  inordinate amount of time debugging obscure corner cases,  not only in Bigtable code, but also in Chubby code. Eventually,  we scrapped this protocol and moved to a newer simpler protocol that depends solely on widely­used Chubby features.” Google Bigtable Paper
  14. 14. obscure featuresexample of a changing feature:my $foo = 1 if $bar;
  15. 15. neverformats
  16. 16. never punctuation variablesmy $text = do { local $/ = undef; <$fh>; };
  17. 17. neverimport functions that dont import use Catalyst qw/­Debug/; use Catalyst ();
  18. 18. never function prototypessub do_it (&@) {  blah blah blah}
  19. 19. neverindirect object syntax new Class    #no Class­>new() #yes
  20. 20. neverUNIVERSAL::
  21. 21. neveralternative inheritance schemes
  22. 22. never re­blessing existing objectsbless, $object, Some::Other::Class;
  23. 23. neverobjects that arent hashes(but maybe Object::InsideOut)
  24. 24. neveroverloading
  25. 25. overloadinguse Exception::Class  qw(MyProject::BadKarma);  # in some method, the exception is triggeredMyProject::BadKarma­>throw();  # in the caller, we catch it with evalif ($@ and $@­>isa(MyProject::BadKarma)) {
  26. 26. nevermultiple packages in one file
  27. 27. neversource filters
  28. 28. never the constant pragmause constant TEA => Darjeeling;%beverages = (TEA => 1);  our $TEA = Darjeeling;%beverages = ($TEA => 1);
  29. 29. never tied variablestie(%h,’SDBM_File’, ’filename’,...);$h{foo} = 1;
  30. 30. rarelyDESTROY methods
  31. 31. rarelyweak references
  32. 32. rarelyAUTOLOAD
  33. 33. rarely wantarray@books = Book­>search(author => $author)    || die "book not found";
  34. 34. sometimes closures
  35. 35. sometimes string eval
  36. 36. sometimes sub attributessub foo : attribute {
  37. 37. sometimescode references
  38. 38. sometimesexported subs
  39. 39. sometimeschained map/grep
  40. 40. sometimes ternary operatormy $foo = $bar ? yes : no;
  41. 41. sometimes $_
  42. 42. questions you might have doesnt this take all the fun out of  programming?
  43. 43. questions you might havewont this make your code longer?
  44. 44. questions you might have but AUTOLOAD is awesome!
  45. 45. questions you might have why dont you just use Java?
  46. 46. beyond the code● configuration management● version control with branches
  47. 47. beyond the code● tests can save your life● Test::Class can save your tests● smolder,  http://sourceforge.net/projects/smolder/
  48. 48. thank you!

×