low-maintenance perl
DESCRIPTION
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.TRANSCRIPT
![Page 1: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/1.jpg)
low maintenance perl“optimizing for an easy life”
perrin harkinsplus three
![Page 2: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/2.jpg)
“i would never use perl for a large project.”
“perl is unmaintainable.”
“perl is writeonly.”
the fud
![Page 3: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/3.jpg)
i shouldn't have to tell you this
use strict;
use warnings;
perltidy
![Page 4: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/4.jpg)
know your audience
“code is always read more times than it is written.”
andy hunt
![Page 5: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/5.jpg)
choosing a dialect
don't use something complex when something simple will work.
![Page 6: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/6.jpg)
choosing a dialect
don't do things in a magical way when an explicit way will work.
![Page 7: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/7.jpg)
choosing a dialect
don't make your code complex just so you can get a certain syntax.
![Page 8: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/8.jpg)
choosing a dialect
fetch("search.cpan.org") > \my @cont;
is equivalent to
my $scraper = FEAR::API>fear();my $page = $scraper>fetch("search.cpan.org");push my @cont, $page>document>as_string;
![Page 9: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/9.jpg)
choosing a dialect
follow conventions when you can.
![Page 10: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/10.jpg)
choosing a dialect
which scans faster?
s{foo}{bar}g;
s/foo/bar/g;
![Page 11: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/11.jpg)
choosing a dialect
don't use an obscure language feature when a common one will work.
![Page 12: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/12.jpg)
choosing a dialect
dragonchild's law:"if i have to ask if something is possible on
perlmonks, i probably should rethink my design."
![Page 13: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/13.jpg)
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 widelyused Chubby features.”Google Bigtable Paper
![Page 14: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/14.jpg)
obscure features
example of a changing feature:
my $foo = 1 if $bar;
![Page 15: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/15.jpg)
never
formats
![Page 16: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/16.jpg)
never
punctuation variables
my $text = do { local $/ = undef; <$fh>; };
![Page 17: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/17.jpg)
never
import functions that don't import
use Catalyst qw/Debug/;
use Catalyst ();
![Page 18: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/18.jpg)
never
function prototypes
sub do_it (&@) { blah blah blah}
![Page 19: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/19.jpg)
never
indirect object syntax
new Class #no
Class>new() #yes
![Page 20: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/20.jpg)
never
UNIVERSAL::
![Page 21: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/21.jpg)
never
alternative inheritance schemes
![Page 22: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/22.jpg)
never
reblessing existing objects
bless, $object, 'Some::Other::Class';
![Page 23: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/23.jpg)
never
objects that aren't hashes
(but maybe Object::InsideOut)
![Page 24: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/24.jpg)
never
overloading
![Page 25: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/25.jpg)
overloading
use 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')) {
![Page 26: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/26.jpg)
never
multiple packages in one file
![Page 27: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/27.jpg)
never
source filters
![Page 28: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/28.jpg)
never
the constant pragma
use constant TEA => 'Darjeeling';%beverages = (TEA => 1); our $TEA = 'Darjeeling';%beverages = ($TEA => 1);
![Page 29: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/29.jpg)
never
tied variables
tie(%h,’SDBM_File’, ’filename’,...);
$h{'foo'} = 1;
![Page 30: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/30.jpg)
rarely
DESTROY methods
![Page 31: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/31.jpg)
rarely
weak references
![Page 32: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/32.jpg)
rarely
AUTOLOAD
![Page 33: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/33.jpg)
rarely
wantarray
@books = Book>search(author => $author) || die "book not found";
![Page 34: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/34.jpg)
sometimes
closures
![Page 35: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/35.jpg)
sometimes
string eval
![Page 36: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/36.jpg)
sometimes
sub attributes
sub foo : attribute {
![Page 37: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/37.jpg)
sometimes
code references
![Page 38: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/38.jpg)
sometimes
exported subs
![Page 39: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/39.jpg)
sometimes
chained map/grep
![Page 40: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/40.jpg)
sometimes
ternary operator
my $foo = $bar ? 'yes' : 'no';
![Page 41: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/41.jpg)
sometimes
$_
![Page 42: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/42.jpg)
questions you might have
doesn't this take all the fun out of programming?
![Page 43: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/43.jpg)
questions you might have
won't this make your code longer?
![Page 44: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/44.jpg)
questions you might have
but AUTOLOAD is awesome!
![Page 45: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/45.jpg)
questions you might have
why don't you just use Java?
![Page 46: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/46.jpg)
beyond the code
● configuration management● version control with branches
![Page 47: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/47.jpg)
beyond the code
● tests can save your life● Test::Class can save your tests● smolder,
http://sourceforge.net/projects/smolder/
![Page 48: Low-Maintenance Perl](https://reader033.vdocuments.mx/reader033/viewer/2022052617/546b295eaf795902048b55e5/html5/thumbnails/48.jpg)
thank you!