SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
low maintenance perl
 “optimizing for an easy life”

         perrin harkins
          plus three
the fud

“i would never use perl for a large project.”
“perl is unmaintainable.”
“perl is write­only.”
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 widely­used 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




       re­blessing 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 triggered
MyProject::BadKarma­>throw();
  
# in the caller, we catch it with eval
if ($@ 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!

Weitere ähnliche Inhalte

Was ist angesagt?

Javascript Ks
Javascript KsJavascript Ks
Javascript Ks
ssetem
 

Was ist angesagt? (19)

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Add Perl to Your Toolbelt
Add Perl to Your ToolbeltAdd Perl to Your Toolbelt
Add Perl to Your Toolbelt
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
What's up in ruby for Java developers
What's up in ruby for Java developersWhat's up in ruby for Java developers
What's up in ruby for Java developers
 
Cucumber & BDD
Cucumber & BDDCucumber & BDD
Cucumber & BDD
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018
Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018
Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018
 
Javascript Ks
Javascript KsJavascript Ks
Javascript Ks
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
 
WordPress Development in a Modern PHP World
WordPress Development in a Modern PHP WorldWordPress Development in a Modern PHP World
WordPress Development in a Modern PHP World
 
Preparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationPreparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for Translation
 
Selenium sandwich-2
Selenium sandwich-2Selenium sandwich-2
Selenium sandwich-2
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Ruby, Meet iPhone
Ruby, Meet iPhoneRuby, Meet iPhone
Ruby, Meet iPhone
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
 
Ajaxworld07
Ajaxworld07Ajaxworld07
Ajaxworld07
 

Ähnlich wie Low-Maintenance Perl

Ähnlich wie Low-Maintenance Perl (20)

The Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitThe Essential Perl Hacker's Toolkit
The Essential Perl Hacker's Toolkit
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 

Mehr von Perrin Harkins

Mehr von Perrin Harkins (13)

PyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to Profiling
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Care and feeding notes
Care and feeding notesCare and feeding notes
Care and feeding notes
 
Scalable talk notes
Scalable talk notesScalable talk notes
Scalable talk notes
 
Low maintenance perl notes
Low maintenance perl notesLow maintenance perl notes
Low maintenance perl notes
 
Choosing a Web Architecture for Perl
Choosing a Web Architecture for PerlChoosing a Web Architecture for Perl
Choosing a Web Architecture for Perl
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with Perl
 
Efficient Shared Data in Perl
Efficient Shared Data in PerlEfficient Shared Data in Perl
Efficient Shared Data in Perl
 
Choosing a Templating System
Choosing a Templating SystemChoosing a Templating System
Choosing a Templating System
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
Care and Feeding of Large Web Applications
Care and Feeding of Large Web ApplicationsCare and Feeding of Large Web Applications
Care and Feeding of Large Web Applications
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance Tips
 
The Most Common Template Toolkit Mistake
The Most Common Template Toolkit MistakeThe Most Common Template Toolkit Mistake
The Most Common Template Toolkit Mistake
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Low-Maintenance Perl