Upload
perrin-harkins
View
377
Download
5
Tags:
Embed Size (px)
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.
Citation preview
low maintenance perl“optimizing for an easy life”
perrin harkinsplus three
“i would never use perl for a large project.”
“perl is unmaintainable.”
“perl is writeonly.”
the fud
i shouldn't have to tell you this
use strict;
use warnings;
perltidy
know your audience
“code is always read more times than it is written.”
andy hunt
choosing a dialect
don't use something complex when something simple will work.
choosing a dialect
don't do things in a magical way when an explicit way will work.
choosing a dialect
don't make your code complex just so you can get a certain syntax.
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;
choosing a dialect
follow conventions when you can.
choosing a dialect
which scans faster?
s{foo}{bar}g;
s/foo/bar/g;
choosing a dialect
don't use an obscure language feature when a common one will work.
choosing a dialect
dragonchild's law:"if i have to ask if something is possible on
perlmonks, i probably should rethink my design."
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
obscure features
example of a changing feature:
my $foo = 1 if $bar;
never
formats
never
punctuation variables
my $text = do { local $/ = undef; <$fh>; };
never
import functions that don't import
use Catalyst qw/Debug/;
use Catalyst ();
never
function prototypes
sub do_it (&@) { blah blah blah}
never
indirect object syntax
new Class #no
Class>new() #yes
never
UNIVERSAL::
never
alternative inheritance schemes
never
reblessing existing objects
bless, $object, 'Some::Other::Class';
never
objects that aren't hashes
(but maybe Object::InsideOut)
never
overloading
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')) {
never
multiple packages in one file
never
source filters
never
the constant pragma
use constant TEA => 'Darjeeling';%beverages = (TEA => 1); our $TEA = 'Darjeeling';%beverages = ($TEA => 1);
never
tied variables
tie(%h,’SDBM_File’, ’filename’,...);
$h{'foo'} = 1;
rarely
DESTROY methods
rarely
weak references
rarely
AUTOLOAD
rarely
wantarray
@books = Book>search(author => $author) || die "book not found";
sometimes
closures
sometimes
string eval
sometimes
sub attributes
sub foo : attribute {
sometimes
code references
sometimes
exported subs
sometimes
chained map/grep
sometimes
ternary operator
my $foo = $bar ? 'yes' : 'no';
sometimes
$_
questions you might have
doesn't this take all the fun out of programming?
questions you might have
won't this make your code longer?
questions you might have
but AUTOLOAD is awesome!
questions you might have
why don't you just use Java?
beyond the code
● configuration management● version control with branches
beyond the code
● tests can save your life● Test::Class can save your tests● smolder,
http://sourceforge.net/projects/smolder/
thank you!