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

Refactoring: Decision making in Rails projects

Refactoring: Decision making in Rails projects

Having more fun, bring more value, and keep things simple.

Jeremy Baker

January 13, 2017
Tweet

More Decks by Jeremy Baker

Other Decks in Programming

Transcript

  1. The limit in any organization isn’t resources or time.
    It’s energy & motivation.
    Tom Chi
    Former Head of Experience - Google X

    View full-size slide

  2. @jhubert
    (RubyConf 2005)

    View full-size slide

  3. Refactoring
    photo by tim marshall
    Changing how the code is written without
    changing what it does.

    View full-size slide

  4. For each desired change, make the change easy
    (warning: this may be hard), then make the easy change.
    Kent Beck
    creator of extreme programming
    twitter.com/kentbeck/status/250733358307500032

    View full-size slide

  5. Steps
    photo by patrick mcmanaman

    View full-size slide

  6. 1. Decide a change should be made
    Steps
    photo by patrick mcmanaman

    View full-size slide

  7. 1. Decide a change should be made
    2. Pick a code smell
    Steps
    photo by patrick mcmanaman

    View full-size slide

  8. Long Method
    Large Class
    Primitive Obsession
    Long Parameter List
    Data Clumps
    Switch Statements
    Temporary Field
    Refused Bequest
    Alternative Classes with Different Interfaces
    Divergent Change
    Shotgun Surgery
    Parallel Inheritance Hierarchies
    Comments
    Duplicate Code
    Lazy Class
    Data Class
    Dead Code
    Speculative Generality
    Feature Envy
    Inappropriate Intimacy
    Message Chains
    Middle Man
    Incomplete Library Class
    photo by pete fabian
    Classic Smells

    View full-size slide

  9. Long Method
    Large Class
    Primitive Obsession
    Long Parameter List
    Data Clumps
    Switch Statements
    Temporary Field
    Refused Bequest
    Alternative Classes with Different Interfaces
    Divergent Change
    Shotgun Surgery
    Parallel Inheritance Hierarchies
    Comments
    Duplicate Code
    Lazy Class
    Data Class
    Dead Code
    Speculative Generality
    Feature Envy
    Inappropriate Intimacy
    Message Chains
    Middle Man
    Incomplete Library Class
    photo by pete fabian
    Classic Smells
    Bloaters Change
    Preventers
    Dispensables
    Couplers
    OO Abusers

    View full-size slide

  10. 1. Decide a change should be made
    2. Pick a code smell
    3. Remove that code smell
    Steps
    photo by patrick mcmanaman

    View full-size slide

  11. 1. Decide a change should be made
    2. Pick a code smell
    3. Remove that code smell
    Steps
    (DO NOT GET DISTRACTED)
    photo by patrick mcmanaman

    View full-size slide

  12. 1. Decide a change should be made
    2. Pick a code smell
    3. Remove that code smell
    4. Repeat until desired change is easy
    Steps
    (DO NOT GET DISTRACTED)
    photo by patrick mcmanaman

    View full-size slide

  13. photo by tj holowaychuck
    nothing to do
    with ruby

    View full-size slide

  14. Better Teachers Exist!
    Try these ruby related shortcuts…
    www.sandimetz.com/99bottles
    www.youtube.com/watch?v=PJjHfa5yxlU
    www.youtube.com/watch?v=59YClXmkCVM
    Sandi Metz - Get a whiff of this
    Katrina Owen - Succession
    www.youtube.com/watch?v=DC-pQPq0acs
    Ben Orenstein - From Good to Great

    View full-size slide

  15. !!
    gist.github.com/tjwallace/16009137fdf103110786b9ba32735fd1
    Recommended config, thanks to @tjwallace from Zozi:

    View full-size slide

  16. photo by ᨬឡد ng
    The product is the behavior change you cause in
    your users. It is not the application you’re building.
    Tom Chi
    Former Head of Experience - Google X

    View full-size slide

  17. photo by annie spratt

    View full-size slide

  18. #1
    photo by nick jio

    View full-size slide

  19. A feature is causing slow page loads.
    We need to speed it up.
    CHANGE
    "

    View full-size slide

  20. I don’t know how to fix this problem.
    Where should I start?
    WHAT’S THE SMELL?
    #

    View full-size slide

  21. The initial time spent implementing a feature is one
    of the least interesting data points to consider
    when weighing the cost and benefit of a feature.
    Kris Gale
    Former VP Eng, Yammer
    firstround.com/review/The-one-cost-engineers-and-product-managers-dont-consider/

    View full-size slide

  22. ...
    toggle: function (list) {
    ga(
    "send",
    “event",
    “Interface”,
    “toggle”,
    “Communication Preview Tasks”
    );
    list.toggleClass('is-expanded');
    }
    ...

    View full-size slide

  23. 3,757 uses
    559,000 views
    ______
    0.67%

    View full-size slide

  24. $
    REMOVE IT!
    Solve the performance problem and never think
    about that feature again.

    View full-size slide

  25. Dead
    Feature
    #1 Courage! %
    photo by nick jio

    View full-size slide

  26. #2
    photo by ricardo viana

    View full-size slide

  27. The deployment is complicated, prone
    to failures, and slow.
    CHANGE
    "

    View full-size slide

  28. I don’t know how to fix this problem.
    Where should I start?
    WHAT’S THE SMELL?
    #

    View full-size slide

  29. There is nothing so useless as doing efficiently that
    which should not be done at all.
    Peter Drucker
    Old-School Management Consultant

    View full-size slide

  30. Is hosting a core competency of ours
    or value we deliver for customers?
    QUESTION
    #

    View full-size slide

  31. • Save time
    • Get peace of mind
    • Less documentation that you need to maintain
    • Less training
    • Less ongoing maintenance
    • Less specialty knowledge
    • Gives you more time to focus on the real value you can deliver

    View full-size slide

  32. Unnecessary
    Innovation
    #2
    photo by ricardo viana

    View full-size slide

  33. #3
    photo by todd quackenbush

    View full-size slide

  34. Add a clickable checkbox to our
    React based task list.
    CHANGE
    &

    View full-size slide

  35. TO THIS
    FROM THIS

    View full-size slide

  36. Dispatcher
    Store
    View
    Action
    React
    View / Serializer
    Model
    Migration
    Rails

    View full-size slide

  37. I don’t know how to fix this problem.
    Where should I start?
    What’s the smell?
    #

    View full-size slide

  38. For each desired change, make the change easy
    (warning: this may be hard), then make the easy change.
    Kent Beck
    creator of extreme programming
    twitter.com/kentbeck/status/250733358307500032

    View full-size slide

  39. Dispatcher
    Store
    View
    Action
    React
    View / Serializer
    Model
    Migration
    Rails

    View full-size slide

  40. Dispatcher
    Store
    View
    Action
    React
    View / Serializer
    Model
    Migration
    Rails
    1,061 lines of JS code
    17 files
    + JS testing
    + Documentation

    + Browser support
    The core application

    View full-size slide

  41. Dispatcher
    Store
    View
    Action
    React
    View / Serializer
    Model
    Migration
    Rails
    WTF?!
    Value

    View full-size slide

  42. View / Serializer
    Model
    Migration
    Rails
    Server-Side JS Responses (.js.slim)
    signalvnoise.com/posts/3697-server-generated-javascript-responses

    View full-size slide

  43. ruby:
    id = ‘#’ + dom_id(@task, :checkbox)
    content = escape_javascript(render(partial: 'shared/task/checkbox', locals: { task: @task }))
    $(‘#{id}’).replaceWith(“#{content)}");
    ruby:
    url = complete_task_path(task_id: task.id, format: :js)
    if task.complete?
    method = :delete
    image_path = 'icons/icon-checkbox-on-blue.png'
    else
    method = :post
    image_path = 'icons/icon-checkbox-off.png'
    = link_to url, remote: true, method: method, id: dom_id(task, :checkbox), class: 'js-checkbox'
    = image_tag image_path
    shared/task/_checkbox.slim
    task_status/create.js.slim

    View full-size slide

  44. Why were we using React
    in the first place?
    QUESTION
    '

    View full-size slide

  45. Shiny
    Hammer
    #3
    photo by todd quackenbush

    View full-size slide

  46. Build things your users love.
    Keep the process as simple as possible.

    View full-size slide

  47. ..a simpler design can suggest simplifying the
    organization and reducing the budget, which can
    be contrary to conventional incentives…
    Mel Conway
    Educator, Author of Conway’s Law
    melconway.com/Home/pdf/simplify.pdf

    View full-size slide

  48. I think I just shed a tear.
    This is GREAT!
    Zipline makes my job
    SO MUCH EASIER!
    VP Operations
    One of the world’s largest retailers
    Communications Director
    One of the world’s largest retailers

    View full-size slide

  49. [Zara doesn’t] run their factories at 100%
    utilization. They realized that running them at 80%
    meant that they could slip projects into the
    pipeline on short notice and ultimately sell more.
    Adam Pisoni
    Former CTO, Yammer
    firstround.com/review/Responsiveness-New-Efficiency/

    View full-size slide

  50. We’re hiring Ruby developers who want
    to make amazing products.
    Jeremy Baker
    [email protected]
    @jhubert
    https://speakerdeck.com/jhubert photos courtesy of unsplash.com

    View full-size slide