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.

Improving code design with automated checks

46 views

Published on

Presented at the Toronto Rails Meetup, June 4th 2019.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Improving code design with automated checks

  1. 1. Improving Code Designwith Automated Checks AndyWaite Engineering ManageratFinanceit financeit.io/careers 1
  2. 2. RuboCop Categories of rules: » Linting » Style » Security » Naming » Metrics @andyw8 2
  3. 3. ASimple PullRequest class Product ... + + def discounted_price + price * 0.5 + end end tests are passing @andyw8 3
  4. 4. RuboCopFailures Offenses: app/models/product.rb:1:1: C: Metrics/ClassLength: Class has too many lines. [101/100] class Product < ApplicationRecord ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @andyw8 4
  5. 5. Configuration # rubocop.yml Metrics/ClassLength: Enabled: false @andyw8 5
  6. 6. 6
  7. 7. Code Smells » Large Class » Long Function » Long Parameter List @andyw8 7
  8. 8. Possible Refactorings For a Large Class: » Extract Class » Replace Type Code With Subclass @andyw8 8
  9. 9. RuboCopMetrics » Metrics/ClassLength » Large Class (default: 100 lines) » Metrics/MethodLength » Long Function (default: 10 lines) » Metrics/ParameterLists (default: 5 params) » Long Parameter List @andyw8 9
  10. 10. RuboCopSays... "Hmm, this class is getting quite large. I wonder if we should refactor it?" @andyw8 10
  11. 11. AutomatingtheWorkflow » Aim is to run RuboCop against each pull request » Tools: Code Climate, HoundCI, Pronto » Review the warnings » Choose to act or ignore @andyw8 11
  12. 12. Summary » Code Metrics can give valuable insights » Make them part of your automated checks » Use them to detect potential Code Smells » Don't make changes only to satisfy RuboCop » But refactor when it makes sense to you » Continually evolve your application's design @andyw8 12
  13. 13. Thanks GitHub/Twitter: @andyw8 awaite@financeit.io 13

×