Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rescue Squad: Rails Edition - Rails Israel 2014

146e52d49d361f85c0945487452fc6a0?s=47 Ben Lovell
November 04, 2014

Rescue Squad: Rails Edition - Rails Israel 2014

146e52d49d361f85c0945487452fc6a0?s=128

Ben Lovell

November 04, 2014
Tweet

Transcript

  1. RESCUE SQUAD RAILS EDITION Rails Israel 2014

  2. @benlovell twitter/github/irc

  3. None
  4. rails sucks

  5. $ rails new life_is_good

  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. I really suck!

  15. Here’s some commits I made just the other day

  16. None
  17. None
  18. ! "

  19. Programming is like skipping merrily between car crashes

  20. ME!

  21. WHY!!!!? !

  22. Team Transience

  23. Make it work Make it right Make it fast

  24. Make it work Make it right Make it fast

  25. Is it done yet? Is it done yet? Is it

    done yet?
  26. !!!

  27. Rails Derailed

  28. None
  29. Changing requirements

  30. sorry Your project is not a special ❄

  31. Quit whining!

  32. No. 1 best job?

  33. None
  34. $ git clone ...

  35. Huge pile of shit?

  36. None
  37. !" GTFO?

  38. 5 Steps

  39. 1 Step

  40. Perception change it!

  41. I see dead people

  42. Being a positive influence

  43. Opinions as pull requests

  44. Broken windows

  45. Strategise

  46. Always leave the camp cleaner than you found it

  47. It’s better to seek forgiveness than ask permission

  48. Docs

  49. 2 step

  50. Metrics

  51. CI

  52. None
  53. !

  54. Effect a style guide

  55. Make it approachable

  56. Rubocop

  57. $ gem install rubocop ~/code/frontend % rubocop Inspecting 313 files

    .....................................................C ...................................................... ...................................................... ...................................................... ...................................................... ........................................... Offenses: app/helpers/profile_helper.rb:2:1: C: Extra empty line detected at body beginning. 313 files inspected, 1 offense detected
  58. Autocorrect?

  59. ~/code/frontend % rubocop -a Inspecting 313 files .....................................................C Offenses: app/helpers/profile_helper.rb:2:1:

    C: [Corrected] Extra empty line detected at body beginning. 313 files inspected, 1 offense detected, 1 offense corrected
  60. Sorcery!

  61. None
  62. Test Coverage

  63. $ gem install SimpleCov

  64. None
  65. You're sitting on a throne of lies

  66. Cyclomatic Complexity

  67. $ gem install metric_fu-Saikuro

  68. Coverage + Cyclomatic Complexity Inform your tests

  69. Duplication Duplication Duplication Duplication

  70. $ gem install flay ~/code/frontend % flay app/**/*.rb -f Total

    score (lower is better) = 256 1) Similar code found in :call (mass = 148) app/controllers/styleguide_controller.rb:63 app/controllers/styleguide_controller.rb:221 2) Similar code found in :defn (mass = 108) app/helpers/application_helper.rb:2 app/helpers/application_helper.rb:9 app/helpers/application_helper.rb:16 app/helpers/application_helper.rb:23 app/helpers/application_helper.rb:30 app/helpers/application_helper.rb:37
  71. Not all duplication

  72. Good DRY Bad DRY

  73. single unambiguous authoritative representation

  74. Churn

  75. $ gem install churn ~/code/blog % churn Files +----------------------------------------------------------+---------------+ |

    file_path | times_changed | +----------------------------------------------------------+---------------+ | Gemfile | 20 | | app/helpers/application_helper.rb | 14 | | app/models/article.rb | 11 | | spec/models/text_filter_spec.rb | 11 | | spec/controllers/articles_controller_spec.rb | 11 | | spec/controllers/setup_controller_spec.rb | 11 | | spec/rails_helper.rb | 10 | | app/models/blog.rb | 10 | | spec/models/article_spec.rb | 10 | | spec/controllers/admin/content_controller_spec.rb | 10 | | spec/helpers/application_helper_spec.rb | 10 | +----------------------------------------------------------+---------------+
  76. Lines of Code

  77. $ rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC

    | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 1995 | 1613 | 34 | 179 | 5 | 7 | | Helpers | 485 | 401 | 0 | 67 | 0 | 3 | | Models | 2793 | 2196 | 45 | 352 | 7 | 4 | | Mailers | 37 | 31 | 1 | 5 | 5 | 4 | | Javascripts | 31894 | 17140 | 0 | 1553 | 0 | 9 | | Libraries | 2455 | 1878 | 85 | 233 | 2 | 6 | | Controller specs | 3468 | 2801 | 0 | 16 | 0 | 173 | | Helper specs | 264 | 213 | 1 | 3 | 3 | 69 | | Lib specs | 247 | 195 | 0 | 0 | 0 | 0 | | Model specs | 3970 | 3241 | 1 | 21 | 21 | 152 | | Routing specs | 109 | 89 | 0 | 0 | 0 | 0 | | Service specs | 125 | 103 | 0 | 0 | 0 | 0 | | Uploader specs | 9 | 8 | 0 | 0 | 0 | 0 | | View specs | 975 | 788 | 0 | 20 | 0 | 37 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 48826 | 30697 | 167 | 2449 | 14 | 10 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 23259 Test LOC: 7438 Code to Test Ratio: 1:0.3
  78. All the metrics! $ gem install metric_fu cane, churn, flog,

    flay, reek roodi, saikuro, code statistics rails best practices
  79. Metric Overflow!

  80. Only capture that you plan to action

  81. Make it known

  82. Dashboard

  83. Gamify

  84. 3 step

  85. Tests

  86. % tree spec/models spec/models ├── authentication_token_spec.rb ├── challenge_spec.rb ├── entry_spec.rb

    ├── facebook_token_spec.rb ├── follow_spec.rb ├── followed_list_spec.rb ├── item_spec.rb ├── list_fulfilment_criterion_spec.rb ├── list_spec.rb ├── prize_spec.rb ├── rating_spec.rb └── user_spec.rb 0 directories, 12 files
  87. require 'test_helper' class UserTest < ActiveSupport::TestCase # test "the truth"

    do # assert true # end end
  88. None
  89. All kinds of bad

  90. No tests Slow tests Low quality tests

  91. Tests are not sacred artifacts

  92. Tests can be transient

  93. zero coverage? this might not be so bad

  94. Feature specs go full stack or go home

  95. Poor or slow units? wrong time, wrong place

  96. Repeat after me: Tests are not sacred artifacts

  97. kill them with fire

  98. 4 step

  99. Seek and destroy

  100. Reduce the surface area

  101. Always be merciless

  102. Metrics

  103. Low hanging fruit Targets or goals which are easily achievable

    but do not require lots of effort
  104. Improve Incrementally

  105. None
  106. Katrina Owen @kytrinyx

  107. If you're especially brave...

  108. $ bundle outdated

  109. 5 step

  110. Keep it full unicorn

  111. Fail the build

  112. Always be improving

  113. Perception Metrics Tests Reduce or Improve Stay Full Unicorn

  114. None
  115. Thanks! @benlovell

  116. None