Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bergrebell/e3723ade94810716ac7a44e41ccba2de to your computer and use it in GitHub Desktop.
Save Bergrebell/e3723ade94810716ac7a44e41ccba2de to your computer and use it in GitHub Desktop.
"In Relentless Pursuit of Rest" from Derek Prior

RailsConf 2017: In Relentless Pursuit of REST by Derek Prior

Slides : https://speakerdeck.com/derekprior/in-relentless-pursuit-of-rest Talk : https://www.youtube.com/watch?v=HctYHe-YjnE

  • REST help rails growing

  • More small things (small models, controllers, services, views...)

  • [Anti-pattern] Custom actions

    • When having noun#verb_noun (users#edit_password, users#update_password) = Missing resource -> Resource is password (password#edit, password#update)
    • Controllers do not need to map to ActiveRecord objects
  • [Anti-pattern] Complex actions

    • Make boring code
    • Less before_actions
    • Use service object, query objects, objects to extract complexity
    • Be boring (boring controller, boring model, ...)
  • [Anti-pattern] Ambiguous language

    • "process"? What does it mean?
    • Order#process -> Shipments#create
    • Don't be scared about duplicate code. "duplication is far cheaper than the wrong abstraction" (cf Sandi Metz)
    • This change Order#process -> Shipments#create create a "breathing room".
  • [Anti-pattern] State Machines

    • Code spaghetti.
    • State machines are magnetic : they attract more states, transitions, events, callbacks and they accumulate callback logic where our bugs hide
    • State machines are not easy to clean
    • What if update didn't exist?
    • Move to REST with a object/service object for the step of state machine
    • Any move to tiner ruby object will be a win
  • Outside in (https://youtu.be/HctYHe-YjnE?t=1696)

    • We changing the language of the applcation from "What this application store, and how this is stored" to "What it this application does" (at a higher level)
    • In most case what's keeping any app from being a CRUD app is a lack of imagination : You have'nt gone back to rethink the problem from the outside to identify the resource you're talking about.
    • Be boring. Be RESTful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment