Refactoring: Decision making in Rails projects

Refactoring: Decision making in Rails projects

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

D51af99491ce4b25b808c44175d8dea2?s=128

Jeremy Baker

January 13, 2017
Tweet

Transcript

  1. The limit in any organization isn’t resources or time. It’s

    energy & motivation. Tom Chi Former Head of Experience - Google X
  2. @jhubert (RubyConf 2005)

  3. None
  4. None
  5. None
  6. None
  7. Refactoring photo by tim marshall Changing how the code is

    written without changing what it does.
  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
  9. Steps photo by patrick mcmanaman

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

    patrick mcmanaman
  11. 1. Decide a change should be made 2. Pick a

    code smell Steps photo by patrick mcmanaman
  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
  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
  14. 1. Decide a change should be made 2. Pick a

    code smell 3. Remove that code smell Steps photo by patrick mcmanaman
  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
  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
  17. photo by tj holowaychuck nothing to do with ruby

  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
  19. !! gist.github.com/tjwallace/16009137fdf103110786b9ba32735fd1 Recommended config, thanks to @tjwallace from Zozi:

  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
  21. photo by annie spratt

  22. #1 photo by nick jio

  23. A feature is causing slow page loads. We need to

    speed it up. CHANGE "
  24. None
  25. None
  26. I don’t know how to fix this problem. Where should

    I start? WHAT’S THE SMELL? #
  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/
  28. ... toggle: function (list) { ga( "send", “event", “Interface”, “toggle”,

    “Communication Preview Tasks” ); list.toggleClass('is-expanded'); } ...
  29. 3,757 uses 559,000 views ______ 0.67%

  30. $ REMOVE IT! Solve the performance problem and never think

    about that feature again.
  31. Dead Feature #1 Courage! % photo by nick jio

  32. #2 photo by ricardo viana

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

    "
  34. TERRAFORM

  35. I don’t know how to fix this problem. Where should

    I start? WHAT’S THE SMELL? #
  36. There is nothing so useless as doing efficiently that which

    should not be done at all. Peter Drucker Old-School Management Consultant
  37. Is hosting a core competency of ours or value we

    deliver for customers? QUESTION #
  38. None
  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
  40. Unnecessary Innovation #2 photo by ricardo viana

  41. #3 photo by todd quackenbush

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

    CHANGE &
  43. TO THIS FROM THIS

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

    Rails
  45. I don’t know how to fix this problem. Where should

    I start? What’s the smell? #
  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
  47. Dispatcher Store View Action React View / Serializer Model Migration

    Rails
  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
  49. Dispatcher Store View Action React View / Serializer Model Migration

    Rails WTF?! Value
  50. View / Serializer Model Migration Rails Server-Side JS Responses (.js.slim)

    signalvnoise.com/posts/3697-server-generated-javascript-responses
  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
  52. Why were we using React in the first place? QUESTION

    '
  53. Shiny Hammer #3 photo by todd quackenbush

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

    as possible.
  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
  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
  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/
  58. We’re hiring Ruby developers who want to make amazing products.

    Jeremy Baker jeremy@retailzipline.com @jhubert https://speakerdeck.com/jhubert photos courtesy of unsplash.com