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

Refactor or Die

Refactor or Die

a Lightning talk @ Ruby Hiroba 2013

2e7087b86608d4497c209eb9ba14d8f5?s=128

Sho Kusano

June 02, 2013
Tweet

Transcript

  1. REFACTOR O R D I E

  2. Sho Kusano @rosylilly Engineer

  3. None
  4. http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers

  5. 1 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Classes can be

    no longer than one hundred lines of code
  6. 2 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Methods can be

    no longer than five lines of code
  7. 3 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Pass no more

    than four parameters into a method. Hash options are parameters.
  8. 4 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Controllers can instantiate

    only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed)
  9. 0 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers You should break

    these rules only if you have a good reason or your pair lets you
  10. Let’s refactor your codes!

  11. None
  12. Where we can start refactoring?

  13. rubocop https://github.com/bbatsov/rubocop Save your coding rules

  14. $ rubocop ... C:264: Surrounding space missing for '{'. C:264:

    Surrounding space missing for '{'. C:264: Space missing to the left of '}'. C:282: Line is too long. [98/79] C:283: Line is too long. [81/79] C:284: Method has too many lines. [45/10] C:287: Prefer single-quoted strings when you don't need string interpolation or special symbols. C:288: Line is too long. [115/79] C:298: Indent when as deep as case. C:300: Indent when as deep as case. C:305: Line is too long. [98/79] C:310: Indent when as deep as case. C:318: Indent when as deep as case. C:320: Indent when as deep as case. ...
  15. simplecov https://github.com/colszowka/simplecov Don’t end with “FIXME”

  16. $ COV=1 rspec spec/models ............................................................... Finished in 1.62 seconds 63

    examples, 0 failures Coverage report generated for RSpec to coverage. 140 / 140 LOC (100.0%) covered.
  17. Module#deprecate http://api.rubyonrails.org/classes/Module.html#method-i-deprecate Don’t get on the time machine

  18. class DirtyModel def old_method # body omitted ... end deprecate

    :old_method def new_method # body omitted ... end if Rails.env.test? alias_method :old_method, :new_method end end
  19. Let’s refactor your codes!

  20. WE ARE HIRING !! Let’s refactor our codes together !!

    http://info.cookpad.com/jobs/?affcd=geo2a
  21. One more dish

  22. 24-hours Hackathon Competition http://info.cookpad.com/24contest4 Twitter: @24contest / Hashtags: #24contest 2013

    / 06 / 15 09:00 a.m. ʙ 06 / 16 09:00 a.m.
  23. Thank you for listening https://speakerdeck.com/rosylilly/refactor-or-die

  24. sora_h my wife Special Thanks