際際滷

際際滷Share a Scribd company logo
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
Error(s) Free Programming
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
Error(s) Free Programming
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
Error(s) Free Programming
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!
Error(s) Free Programming
But
Error(s) Free Programming
0 errors
or
no errors
Error(s) Free Programming
<#:$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
Error(s) Free Programming
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
Error(s) Free Programming
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
Error(s) Free Programming
<#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
Error(s) Free Programming
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
Error(s) Free Programming
Our users
cant 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) {

}
Error(s) Free Programming
inflect()
Lazy
Good enough
isn't
good enough
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
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

More Related Content

Error(s) Free Programming