SlideShare a Scribd company logo
Clean Code Hendrik Van Belleghem Belgian Perl Workshop 2007
Itโ€™s all Bruces fault!
Obviously? Pragmas warnings strict subs  : no barewords! refs  : no symbolic references! vars  : no undeclared variables!
Obviously? Variable names Variable names should be Short but not too short $i, $a, $o Unambiguous $i, $data, $line
Obviously? Variable names Variable names should definitely not be generated by Acme::MetaSyntactic: $thwacke   # batman $flrbbbbb  # batman $bondelschwaartz   #pynchon $ununquadium  # elements
Acme::Metasyntactic? Itโ€™s all BooKโ€™s fault!
Obviously? Variable names Scalars are single $item Hashes and arrays are plural @items Mark booleans with test $found_match Add reference prefix/suffix $item_ref
Braces.. bad? Array definition my @list =  ( โ€˜larryโ€™,  โ€˜ damianโ€™ ); Any other block? for my $coder ( @list )  { print โ€œhi $coder\nโ€; }
Braces..good? Array definition my @list = ( โ€˜ larryโ€™, โ€˜ damianโ€™ ); Any other block? for my $coder ( @list ) { print โ€œhi $coder\nโ€;  }
Stay away from $_ $_ as default argument? -X, abs, alarm, chomp, chop, chr, chroot, cos, defined, eval, exp, glob, hex, int, lc, lcfirst, length, log, lstat, oct , ord, pos, print, quotemeta, readlink, ref, require, reverse, rmdir, sin, split, sqrt, stat, study, uc, ucfirst, unlink Implicit use m//, s///, y/// for(), map {}, grep {}, while(<>) default input and pattern matching space
Postfix if buy(&quot;secret lair&quot;) and buy(&quot;sharks with lasers&quot;)  and $mini_me = clone() if $goal eq &quot;world domination&quot;; if ($goal eq โ€œworld dominationโ€) { buy(โ€œsecret lairโ€);  buy(โ€œsharks with lasersโ€); $mini_me = clone(); }
C style loops for (my $slide = 1; $slide < 25 ; $slide++) { present($slide); } for my $slide (1..25) { present($slide); } Cleaner Easier to read
POD Put POD in the source file.. At the end Check your POD! Podchecker Use POD templates & stubs NAME, VERSION, SYNOPSIS,..
String eval is bad Donโ€™t overuse eval.. Period String eval is recompiled on execution Use block instead Are you taint-checking??
Filehandles Bareword filehandles Cannot be localized Passing it to a sub? Try typeglobs Better: indirect filehandles From 5.6 onwards open my $filehandle, โ€<filenameโ€ or die $!;
Regexp::Common IP addresses? $ip =~ /$RE{net}{IPv4}/ MAC addresses? $ip =~ /$RE{net}{MAC}/ Credit cards $number =~ /$RE{zip}{VISA}/ For all your extraordinary regexp needs
Regexp::Common? Itโ€™s all Abigails fault! Dutch Tall Strapping hunk of  manhood For all your extraordinary regexp needs
Regexp Delimiters Question.. What does this do? harry s truman was the 33rd u.s. president; harry s |ruman was |he 33rd u.s. presiden|; harry($string =~ s{ruman was }{he 33rd u.s. presiden}xms);
Regexp Keep it simple! $foo =~ s{foo}{bar}g; $html =~ s/<(?:[^>'&quot;]*|(['&quot;]).*?\1)*>//gsx Add comments to big Regexp chunks Use  \A  and  \Z  instead of  $  and  ^ s{ <  # opening angle bracket (?:  # Non-backreffing grouping paren [^>'&quot;] *  # 0 or more things that are neither > nor ' nor &quot; |  #  or else &quot;.*?&quot;  # a section between double quotes (stingy match) |  #  or else '.*?'  # a section between single quotes (stingy match) ) +  #  all occurring one or more times >  # closing angle bracket }{}gsx;  # replace with nothing, i.e. delete
Autoload Inheritence precedence? Catch all method
Refactoring Original code Duplicated code Move to subroutines Duplicated subroutines Move to packages No overkill!
Tests Write tests first Test::Simple & Test::More Test for failures Test the obvious & not so obvious Find a bug? Write a test!
Version control Multiple developers Undo Generate patches Merging/branching CVS, Subversion, RCS, Perforce, BitKeeper, git
Format Compile time definition No runtime changes Except with eval Global variables only Output to named filehandle
Tie Unknown magic Unpredictable behavior Eg: Tie::Scalar::RestrictUpdates limits changes Slow Change variable behavior through code
Perl::Critic As Module As command line tool As website : http://perlcritic.com DIY Configurable
Perl::Critic As Module use Perl::Critic; my $file = shift; my $critic = Perl::Critic->new(); my @violations = $critic->critique($file); print @violations;
Perl::Critic As command line tool lenore:~$ perlcritic -stern strict.pm  Code before strictures are enabled at line 3, column 1.  See page 429 of PBP.  (Severity: 5) Code before warnings are enabled at line 3, column 1.  See page 431 of PBP.  (Severity: 4) Always unpack @_ first at line 11, column 1.  See page 178 of PBP.  (Severity: 4) Subroutine does not end with &quot;return&quot; at line 11, column 1.  See page 197 of PBP.  (Severity: 4) Always unpack @_ first at line 27, column 1.  See page 178 of PBP.  (Severity: 4) Subroutine does not end with &quot;return&quot; at line 27, column 1.  See page 197 of PBP.  (Severity: 4) Always unpack @_ first at line 32, column 1.  See page 178 of PBP.  (Severity: 4) Subroutine does not end with &quot;return&quot; at line 32, column 1.  See page 197 of PBP.  (Severity: 4)
Perl::Critic As website : http://perlcritic.com
Perl::Critic As Module As command line tool As website : http://perlcritic.com DIY Lots of policies Configurable
Thank you! ใฉใ†ใ‚‚ใ‚ใ‚ŠใŒใจใ†ใƒŸใ‚นใ‚ฟใƒผใƒญใƒœใƒƒใƒˆ (domo arigato, Mr Roboto)
Ad

More Related Content

What's hot (20)

Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson
ย 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
Nirajan Pant
ย 
Syntax
SyntaxSyntax
Syntax
Krasimir Berov (ะšั€ะฐัะธะผะธั€ ะ‘ะตั€ะพะฒ)
ย 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
ย 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
Dave Cross
ย 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
ย 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
Yogesh Sawant
ย 
Grep
GrepGrep
Grep
Dr.M.Karthika parthasarathy
ย 
Perl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally InsanePerl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally Insane
Ricardo Signes
ย 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
Bozhidar Boshnakov
ย 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
Sopan Shewale
ย 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
xSawyer
ย 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
ย 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
Dave Cross
ย 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
Mike Friedman
ย 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf9240
ย 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
Core Lee
ย 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
ย 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
Mike Friedman
ย 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
ย 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson
ย 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
Nirajan Pant
ย 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
ย 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
Dave Cross
ย 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
ย 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
Yogesh Sawant
ย 
Perl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally InsanePerl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally Insane
Ricardo Signes
ย 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
Sopan Shewale
ย 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
xSawyer
ย 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
ย 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
Dave Cross
ย 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
Mike Friedman
ย 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf9240
ย 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
Core Lee
ย 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
ย 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
Mike Friedman
ย 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
ย 

Similar to Cleancode (20)

Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
Marcos Rebelo
ย 
Modern Perl
Modern PerlModern Perl
Modern Perl
Marcos Rebelo
ย 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
NBACriteria2SICET
ย 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
ย 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
Dave Cross
ย 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
Dave Cross
ย 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
Dave Cross
ย 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
Bo Hua Yang
ย 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Dave Cross
ย 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
Mike Bowler
ย 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
Workhorse Computing
ย 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
ย 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
brian d foy
ย 
Php2
Php2Php2
Php2
Keennary Pungyera
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Sway Wang
ย 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
CodeIgniter Conference
ย 
Basic PHP
Basic PHPBasic PHP
Basic PHP
Todd Barber
ย 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs
ย 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
Marcos Rebelo
ย 
Modern Perl
Modern PerlModern Perl
Modern Perl
Marcos Rebelo
ย 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
NBACriteria2SICET
ย 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
ย 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
Dave Cross
ย 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
Dave Cross
ย 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
Dave Cross
ย 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
Bo Hua Yang
ย 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Dave Cross
ย 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
Mike Bowler
ย 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
Workhorse Computing
ย 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
ย 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
brian d foy
ย 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Sway Wang
ย 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
CodeIgniter Conference
ย 
Basic PHP
Basic PHPBasic PHP
Basic PHP
Todd Barber
ย 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs
ย 
Ad

More from hendrikvb (6)

Mojo โ€“ Simple REST Server
Mojo โ€“ Simple REST ServerMojo โ€“ Simple REST Server
Mojo โ€“ Simple REST Server
hendrikvb
ย 
China.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hackChina.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hack
hendrikvb
ย 
Source Filters in Perl 2010
Source Filters in Perl 2010Source Filters in Perl 2010
Source Filters in Perl 2010
hendrikvb
ย 
Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003
hendrikvb
ย 
Json In 5 Slices.Key
Json In 5 Slices.KeyJson In 5 Slices.Key
Json In 5 Slices.Key
hendrikvb
ย 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
ย 
Mojo โ€“ Simple REST Server
Mojo โ€“ Simple REST ServerMojo โ€“ Simple REST Server
Mojo โ€“ Simple REST Server
hendrikvb
ย 
China.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hackChina.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hack
hendrikvb
ย 
Source Filters in Perl 2010
Source Filters in Perl 2010Source Filters in Perl 2010
Source Filters in Perl 2010
hendrikvb
ย 
Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003
hendrikvb
ย 
Json In 5 Slices.Key
Json In 5 Slices.KeyJson In 5 Slices.Key
Json In 5 Slices.Key
hendrikvb
ย 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
ย 
Ad

Recently uploaded (20)

Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
ย 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
ย 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
ย 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
ย 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
ย 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
HCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
HCL Nomad Web โ€“ Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
HCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
panagenda
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
ย 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
ย 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
ย 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
ย 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
ย 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
HCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
HCL Nomad Web โ€“ Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
HCL Nomad Web โ€“ Best Practices and Managing Multiuser Environments
panagenda
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 

Cleancode

  • 1. Clean Code Hendrik Van Belleghem Belgian Perl Workshop 2007
  • 3. Obviously? Pragmas warnings strict subs : no barewords! refs : no symbolic references! vars : no undeclared variables!
  • 4. Obviously? Variable names Variable names should be Short but not too short $i, $a, $o Unambiguous $i, $data, $line
  • 5. Obviously? Variable names Variable names should definitely not be generated by Acme::MetaSyntactic: $thwacke # batman $flrbbbbb # batman $bondelschwaartz #pynchon $ununquadium # elements
  • 7. Obviously? Variable names Scalars are single $item Hashes and arrays are plural @items Mark booleans with test $found_match Add reference prefix/suffix $item_ref
  • 8. Braces.. bad? Array definition my @list = ( โ€˜larryโ€™, โ€˜ damianโ€™ ); Any other block? for my $coder ( @list ) { print โ€œhi $coder\nโ€; }
  • 9. Braces..good? Array definition my @list = ( โ€˜ larryโ€™, โ€˜ damianโ€™ ); Any other block? for my $coder ( @list ) { print โ€œhi $coder\nโ€; }
  • 10. Stay away from $_ $_ as default argument? -X, abs, alarm, chomp, chop, chr, chroot, cos, defined, eval, exp, glob, hex, int, lc, lcfirst, length, log, lstat, oct , ord, pos, print, quotemeta, readlink, ref, require, reverse, rmdir, sin, split, sqrt, stat, study, uc, ucfirst, unlink Implicit use m//, s///, y/// for(), map {}, grep {}, while(<>) default input and pattern matching space
  • 11. Postfix if buy(&quot;secret lair&quot;) and buy(&quot;sharks with lasers&quot;) and $mini_me = clone() if $goal eq &quot;world domination&quot;; if ($goal eq โ€œworld dominationโ€) { buy(โ€œsecret lairโ€); buy(โ€œsharks with lasersโ€); $mini_me = clone(); }
  • 12. C style loops for (my $slide = 1; $slide < 25 ; $slide++) { present($slide); } for my $slide (1..25) { present($slide); } Cleaner Easier to read
  • 13. POD Put POD in the source file.. At the end Check your POD! Podchecker Use POD templates & stubs NAME, VERSION, SYNOPSIS,..
  • 14. String eval is bad Donโ€™t overuse eval.. Period String eval is recompiled on execution Use block instead Are you taint-checking??
  • 15. Filehandles Bareword filehandles Cannot be localized Passing it to a sub? Try typeglobs Better: indirect filehandles From 5.6 onwards open my $filehandle, โ€<filenameโ€ or die $!;
  • 16. Regexp::Common IP addresses? $ip =~ /$RE{net}{IPv4}/ MAC addresses? $ip =~ /$RE{net}{MAC}/ Credit cards $number =~ /$RE{zip}{VISA}/ For all your extraordinary regexp needs
  • 17. Regexp::Common? Itโ€™s all Abigails fault! Dutch Tall Strapping hunk of manhood For all your extraordinary regexp needs
  • 18. Regexp Delimiters Question.. What does this do? harry s truman was the 33rd u.s. president; harry s |ruman was |he 33rd u.s. presiden|; harry($string =~ s{ruman was }{he 33rd u.s. presiden}xms);
  • 19. Regexp Keep it simple! $foo =~ s{foo}{bar}g; $html =~ s/<(?:[^>'&quot;]*|(['&quot;]).*?\1)*>//gsx Add comments to big Regexp chunks Use \A and \Z instead of $ and ^ s{ < # opening angle bracket (?: # Non-backreffing grouping paren [^>'&quot;] * # 0 or more things that are neither > nor ' nor &quot; | # or else &quot;.*?&quot; # a section between double quotes (stingy match) | # or else '.*?' # a section between single quotes (stingy match) ) + # all occurring one or more times > # closing angle bracket }{}gsx; # replace with nothing, i.e. delete
  • 21. Refactoring Original code Duplicated code Move to subroutines Duplicated subroutines Move to packages No overkill!
  • 22. Tests Write tests first Test::Simple & Test::More Test for failures Test the obvious & not so obvious Find a bug? Write a test!
  • 23. Version control Multiple developers Undo Generate patches Merging/branching CVS, Subversion, RCS, Perforce, BitKeeper, git
  • 24. Format Compile time definition No runtime changes Except with eval Global variables only Output to named filehandle
  • 25. Tie Unknown magic Unpredictable behavior Eg: Tie::Scalar::RestrictUpdates limits changes Slow Change variable behavior through code
  • 26. Perl::Critic As Module As command line tool As website : http://perlcritic.com DIY Configurable
  • 27. Perl::Critic As Module use Perl::Critic; my $file = shift; my $critic = Perl::Critic->new(); my @violations = $critic->critique($file); print @violations;
  • 28. Perl::Critic As command line tool lenore:~$ perlcritic -stern strict.pm Code before strictures are enabled at line 3, column 1. See page 429 of PBP. (Severity: 5) Code before warnings are enabled at line 3, column 1. See page 431 of PBP. (Severity: 4) Always unpack @_ first at line 11, column 1. See page 178 of PBP. (Severity: 4) Subroutine does not end with &quot;return&quot; at line 11, column 1. See page 197 of PBP. (Severity: 4) Always unpack @_ first at line 27, column 1. See page 178 of PBP. (Severity: 4) Subroutine does not end with &quot;return&quot; at line 27, column 1. See page 197 of PBP. (Severity: 4) Always unpack @_ first at line 32, column 1. See page 178 of PBP. (Severity: 4) Subroutine does not end with &quot;return&quot; at line 32, column 1. See page 197 of PBP. (Severity: 4)
  • 29. Perl::Critic As website : http://perlcritic.com
  • 30. Perl::Critic As Module As command line tool As website : http://perlcritic.com DIY Lots of policies Configurable