Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Error(s) Free Programming

A talk about writing better messages in Perl.

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

  • Identifiez-vous pour voir les commentaires

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

×