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

Refactor or Die

Refactor or Die

a Lightning talk @ Ruby Hiroba 2013

Sho Kusano

June 02, 2013
Tweet

More Decks by Sho Kusano

Other Decks in Programming

Transcript

  1. REFACTOR
    O R
    D I E

    View Slide

  2. Sho Kusano
    @rosylilly
    Engineer

    View Slide

  3. View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

  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)

    View Slide

  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

    View Slide

  10. Let’s refactor
    your codes!

    View Slide

  11. View Slide

  12. Where we can start refactoring?

    View Slide

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

    View Slide

  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.
    ...

    View Slide

  15. simplecov
    https://github.com/colszowka/simplecov
    Don’t end with “FIXME”

    View Slide

  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.

    View Slide

  17. Module#deprecate
    http://api.rubyonrails.org/classes/Module.html#method-i-deprecate
    Don’t get on the time machine

    View Slide

  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

    View Slide

  19. Let’s refactor
    your codes!

    View Slide

  20. WE ARE
    HIRING !!
    Let’s refactor our codes together !!
    http://info.cookpad.com/jobs/?affcd=geo2a

    View Slide

  21. One more dish

    View Slide

  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.

    View Slide

  23. Thank you for listening
    https://speakerdeck.com/rosylilly/refactor-or-die

    View Slide

  24. sora_h
    my wife
    Special Thanks

    View Slide