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 Slide

  2. @jhubert
    (RubyConf 2005)

    View Slide

  3. View Slide

  4. View Slide

  5. View Slide

  6. View Slide

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

    View Slide

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

  9. Steps
    photo by patrick mcmanaman

    View Slide

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

    View Slide

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

    View Slide

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

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

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

    View Slide

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

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

  17. photo by tj holowaychuck
    nothing to do
    with ruby

    View Slide

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

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

    View Slide

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

  21. photo by annie spratt

    View Slide

  22. #1
    photo by nick jio

    View Slide

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

    View Slide

  24. View Slide

  25. View Slide

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

    View Slide

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

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  32. #2
    photo by ricardo viana

    View Slide

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

    View Slide

  34. TERRAFORM

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  38. View Slide

  39. • 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 Slide

  40. Unnecessary
    Innovation
    #2
    photo by ricardo viana

    View Slide

  41. #3
    photo by todd quackenbush

    View Slide

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

    View Slide

  43. TO THIS
    FROM THIS

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

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

    View Slide

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

    View Slide

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

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

    View Slide

  53. Shiny
    Hammer
    #3
    photo by todd quackenbush

    View Slide

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

    View Slide

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

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

  57. [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 Slide

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