SlideShare une entreprise Scribd logo
1  sur  108
Télécharger pour lire hors ligne
Error(s) Free
Programming
Dave Cross
@davorg / @perlhacks
dave@perlhacks.com
We all
do it
“There was
1 error(s)”
“You have 3
message(s)
waiting”
Good
enough
Is it?
Bad
English
txtspk
“Good enough”
isn't
good enough
Why do
we do it?
Lazy
if ($count == 1) {
$word = 'error';
} else {
$word = 'errors';
}
$word = 'error';
$word .= 's'
if $count != 1;
Tedious
There is a
solution
Lingua::EN::Inflexion
Inflects
words for
you
Nouns
Nouns
(Things)
Verbs
Verbs
(Actions)
Adjectives
Adjectives
(Descriptions)
$word = noun('error');
say $word->singular; # error
say $word->plural; # errors
$word = verb('was');
say $word->singular; # was
say $word->plural; # were
$word = adj('our');
say $word->singular; # my
say $word->plural; # our
Knows
grammar
noun("uncle")->indef_article(); # "an"
noun("union")->indef_article(); # "a"
noun("house")->indef_article(); # "a"
noun("hours")->indef_article(); # "an"
as_regex()
$text =~ noun('cow')->as_regex
$text =~ noun('cow')
say noun('cow')->as_regex
# (?^i:kine|cows|cow)
say noun('cow')->as_regex
# (?^i:kine|cows|cow)
Does this
help?
Not
Really!
$word = noun('error');
if ($count == 1) {
say $word->singular;
} else {
say $word->plural;
}
$word = noun('error');
my $method =
(count == 1) ?
‘singular’ :
‘plural’;
say $word->$method;
No
Simpler
Easier
interface
inflect()
inflect(“<#:$count>
<N:error>
<V:were>
found”);
for (0 .. 5) {
inflect(“<#:$_>
<N:error>
<V:were>
found”);
}
0 errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
0 errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
0 errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
inflect(“<#:$count>
<N:error>
<V:were>
found”);
inflect(“<#:$count>
<N:error>
<V:were>
found”);
<#:$count>
<N:error>
<V:were>
<#:$count>
<N:error>
<V:were>
<#:$count>
<N:error>
<V:were>
<#:$count>
<N:error>
<V:were>
<#:$count>
<N:error>
<V:were>
<A:our>
0 errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
Job Done!
But
0 errors
or
no errors
<#:$count>
<#xx:$count>
<#xx:$count>
<#n:$count>
no errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
no errors were found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
no errors
or
no error
<#s:$count>
no error was found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
no error was found
1 error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
1 error
or
an error
<#a:$count>
0 errors were found
an error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
0 errors were found
an error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
<#an:$count>
no errors were found
an error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
no errors were found
an error was found
2 errors were found
3 errors were found
4 errors were found
5 errors were found
Words or
Numbers?
<#w:$count>
zero errors were found
one error was found
two errors were found
three errors were found
four errors were found
five errors were found
zero errors were found
one error was found
two errors were found
three errors were found
four errors were found
five errors were found
Our users
can’t count
WTF
“f*** the
users”
<#f:$count>
no errors were found
one error was found
a couple of errors were found
a few errors were found
several errors were found
many errors were found
no errors were found
one error was found
a couple of errors were found
a few errors were found
several errors were found
many errors were found
for (0, 1, 2, 4, 7, 10) {
…
}
inflect()
Lazy
“Good enough”
isn't
good enough
Damianware Merchandise
perlhacks.com/damian
All profits go to The Perl Foundation
Error(s) Free
Programming
Dave Cross
@davorg / @perlhacks
dave@perlhacks.com
Error(s) Free Programming

Contenu connexe

Plus de Dave Cross

Object-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and MooseObject-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and Moose
Dave Cross
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
Dave Cross
 

Plus de Dave Cross (20)

Measuring the Quality of Your Perl Code
Measuring the Quality of Your Perl CodeMeasuring the Quality of Your Perl Code
Measuring the Quality of Your Perl Code
 
Apollo 11 at 50 - A Simple Twitter Bot
Apollo 11 at 50 - A Simple Twitter BotApollo 11 at 50 - A Simple Twitter Bot
Apollo 11 at 50 - A Simple Twitter Bot
 
Monoliths, Balls of Mud and Silver Bullets
Monoliths, Balls of Mud and Silver BulletsMonoliths, Balls of Mud and Silver Bullets
Monoliths, Balls of Mud and Silver Bullets
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
I'm A Republic (Honest!)
I'm A Republic (Honest!)I'm A Republic (Honest!)
I'm A Republic (Honest!)
 
Web Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your GooglejuiceWeb Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your Googlejuice
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Freeing Tower Bridge
Freeing Tower BridgeFreeing Tower Bridge
Freeing Tower Bridge
 
Modern Perl Catch-Up
Modern Perl Catch-UpModern Perl Catch-Up
Modern Perl Catch-Up
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Conference Driven Publishing
Conference Driven PublishingConference Driven Publishing
Conference Driven Publishing
 
TwittElection
TwittElectionTwittElection
TwittElection
 
Perl in the Internet of Things
Perl in the Internet of ThingsPerl in the Internet of Things
Perl in the Internet of Things
 
Return to the Kingdom of the Blind
Return to the Kingdom of the BlindReturn to the Kingdom of the Blind
Return to the Kingdom of the Blind
 
Github, Travis-CI and Perl
Github, Travis-CI and PerlGithub, Travis-CI and Perl
Github, Travis-CI and Perl
 
Object-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and MooseObject-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and Moose
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
 
Modern Perl for Non-Perl Programmers
Modern Perl for Non-Perl ProgrammersModern Perl for Non-Perl Programmers
Modern Perl for Non-Perl Programmers
 
Matt's PSGI Archive
Matt's PSGI ArchiveMatt's PSGI Archive
Matt's PSGI Archive
 
The Kingdom of the Blind
The Kingdom of the BlindThe Kingdom of the Blind
The Kingdom of the Blind
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 

Error(s) Free Programming