Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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("h...
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 error...
zero errors were found
one error was found
two errors were found
three errors were found
four errors were found
five error...
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
m...
no errors were found
one error was found
a couple of errors were found
a few errors were found
several errors were found
m...
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
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
Error(s) Free Programming
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
Perl and Elasticsearch
Next
Upcoming SlideShare
Perl and Elasticsearch
Next
Download to read offline and view in fullscreen.

Share

Error(s) Free Programming

Download to read offline

A talk about writing better messages in Perl.

Presented at YAPC Europe in Cluj-Napoca, Romania and at the London Perl Workshop in 2016.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Error(s) Free Programming

  1. 1. Error(s) Free Programming Dave Cross @davorg / @perlhacks dave@perlhacks.com
  2. 2. We all do it
  3. 3. “There was 1 error(s)”
  4. 4. “You have 3 message(s) waiting”
  5. 5. Good enough
  6. 6. Is it?
  7. 7. Bad English
  8. 8. txtspk
  9. 9. “Good enough” isn't good enough
  10. 10. Why do we do it?
  11. 11. Lazy
  12. 12. if ($count == 1) { $word = 'error'; } else { $word = 'errors'; }
  13. 13. $word = 'error'; $word .= 's' if $count != 1;
  14. 14. Tedious
  15. 15. There is a solution
  16. 16. Lingua::EN::Inflexion
  17. 17. Inflects words for you
  18. 18. Nouns
  19. 19. Nouns (Things)
  20. 20. Verbs
  21. 21. Verbs (Actions)
  22. 22. Adjectives
  23. 23. Adjectives (Descriptions)
  24. 24. $word = noun('error'); say $word->singular; # error say $word->plural; # errors
  25. 25. $word = verb('was'); say $word->singular; # was say $word->plural; # were
  26. 26. $word = adj('our'); say $word->singular; # my say $word->plural; # our
  27. 27. Knows grammar
  28. 28. noun("uncle")->indef_article(); # "an" noun("union")->indef_article(); # "a" noun("house")->indef_article(); # "a" noun("hours")->indef_article(); # "an"
  29. 29. as_regex()
  30. 30. $text =~ noun('cow')->as_regex
  31. 31. $text =~ noun('cow')
  32. 32. say noun('cow')->as_regex # (?^i:kine|cows|cow)
  33. 33. say noun('cow')->as_regex # (?^i:kine|cows|cow)
  34. 34. Does this help?
  35. 35. Not Really!
  36. 36. $word = noun('error'); if ($count == 1) { say $word->singular; } else { say $word->plural; }
  37. 37. $word = noun('error'); my $method = (count == 1) ? ‘singular’ : ‘plural’; say $word->$method;
  38. 38. No Simpler
  39. 39. Easier interface
  40. 40. inflect()
  41. 41. inflect(“<#:$count> <N:error> <V:were> found”);
  42. 42. for (0 .. 5) { inflect(“<#:$_> <N:error> <V:were> found”); }
  43. 43. 0 errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  44. 44. 0 errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  45. 45. 0 errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  46. 46. inflect(“<#:$count> <N:error> <V:were> found”);
  47. 47. inflect(“<#:$count> <N:error> <V:were> found”);
  48. 48. <#:$count> <N:error> <V:were>
  49. 49. <#:$count> <N:error> <V:were>
  50. 50. <#:$count> <N:error> <V:were>
  51. 51. <#:$count> <N:error> <V:were>
  52. 52. <#:$count>
  53. 53. <N:error>
  54. 54. <V:were>
  55. 55. <A:our>
  56. 56. 0 errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  57. 57. Job Done!
  58. 58. But
  59. 59. 0 errors or no errors
  60. 60. <#:$count>
  61. 61. <#xx:$count>
  62. 62. <#xx:$count>
  63. 63. <#n:$count>
  64. 64. no errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  65. 65. no errors were found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  66. 66. no errors or no error
  67. 67. <#s:$count>
  68. 68. no error was found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  69. 69. no error was found 1 error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  70. 70. 1 error or an error
  71. 71. <#a:$count>
  72. 72. 0 errors were found an error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  73. 73. 0 errors were found an error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  74. 74. <#an:$count>
  75. 75. no errors were found an error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  76. 76. no errors were found an error was found 2 errors were found 3 errors were found 4 errors were found 5 errors were found
  77. 77. Words or Numbers?
  78. 78. <#w:$count>
  79. 79. zero errors were found one error was found two errors were found three errors were found four errors were found five errors were found
  80. 80. zero errors were found one error was found two errors were found three errors were found four errors were found five errors were found
  81. 81. Our users can’t count
  82. 82. WTF
  83. 83. “f*** the users”
  84. 84. <#f:$count>
  85. 85. 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
  86. 86. 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
  87. 87. for (0, 1, 2, 4, 7, 10) { … }
  88. 88. inflect()
  89. 89. Lazy
  90. 90. “Good enough” isn't good enough
  91. 91. Damianware Merchandise perlhacks.com/damian All profits go to The Perl Foundation
  92. 92. Error(s) Free Programming Dave Cross @davorg / @perlhacks dave@perlhacks.com
  • IoanRogers

    Oct. 24, 2016

A talk about writing better messages in Perl. Presented at YAPC Europe in Cluj-Napoca, Romania and at the London Perl Workshop in 2016.

Views

Total views

4,286

On Slideshare

0

From embeds

0

Number of embeds

2,908

Actions

Downloads

14

Shares

0

Comments

0

Likes

1

×