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

[Saint-P RubyConf 2021] Rails X

[Saint-P RubyConf 2021] Rails X

Rails 7 is just around the corner. Although it brings a lot of powerful features, the new major release is not a revolution. Rails stays omakase; the Rails way is still a monolithic journey.

Let's turn the imagination mode on, and take a look at the fantastic future Rails: composable, extendable, free of core_ext, but still as easy to to use as today.

Vladimir Dementyev

June 05, 2021
Tweet

More Decks by Vladimir Dementyev

Other Decks in Programming

Transcript

  1. Vova on Rails, since 2014
    > 2

    View full-size slide

  2. YEARS AGO
    3
    The grass was greener, the light was brighter
    >

    View full-size slide

  3. Bozhidar is challenging Matz and Ruby Core team (RubyConfBY 2017)
    > 4

    View full-size slide

  4. If there is a gun hanging on the wall in the first act, it must fire in the last
    > 5

    View full-size slide

  5. NOW
    The idea has been on a shelf fo(u)r years
    > 6

    View full-size slide

  6. I didn't expect anyone to vote for this topic 🙀
    > 7

    View full-size slide

  7. Have I been trying to accomplish the quest for an ideal Rails X all these years 🤔
    > 8

    View full-size slide

  8. Rails X == Rails 🤔
    > 9

    View full-size slide

  9. Rails X == Hanami 😸
    > 10

    View full-size slide

  10. MY RAILS X
    Reconsidering the past, designing the future (and some bikeshedding)
    > 11

    View full-size slide

  11. RECONSIDER
    rails new --skip-sprockets --skip-actiontext --skip-turbolinks --skip-actionmailbox --skip-wtf
    >

    View full-size slide

  12. EXTRACTION CURSE
    13
    A combination of extractions is not a framework, it's a Frankenstein 🧟
    >

    View full-size slide

  13. Rails codebase is mostly an extraction (Basecamp
    with Shopify & GitHub sprinkles)
    Extractions are often too host-specific
    14
    The Extraction Curse

    View full-size slide

  14. Non-extractions
    Rails API
    Zeitwerk
    Active Record internals refactoring by @sgrif
    Action Cable Testing 🙂
    15

    View full-size slide

  15. EXTRACTIONS FEATURES
    17

    View full-size slide

  16. OMAKASE CURSE
    18
    Shut up and eat what's on the table!
    >

    View full-size slide

  17. Rails is bloating from the features most users
    don't need
    More code 㱺 more maintenance burden 㱺 less
    time for improvements
    19

    View full-size slide

  18. Dead weight detected ☠
    > 20

    View full-size slide

  19. SEPARATE ECOSYSTEM
    FROM FRAMEWORK
    21

    View full-size slide

  20. 22
    ⚠ Uwaga! PHP is on the next slide!

    View full-size slide

  21. 23
    The student has surpassed the teacher (
    >

    View full-size slide

  22. Tender age in bloom 🌸
    > 24

    View full-size slide

  23. DUAL STACK CURSE
    25
    Two heads are better worse than one
    >

    View full-size slide

  24. 26
    "The first thing we do is tell them to do a bunch of configuration."-Steve Klabnik
    >
    2021

    View full-size slide

  25. 27
    rails new --test-with=rspec
    and/or

    View full-size slide

  26. IMAGINARY FUTURE
    28
    It's time to turn imagination mode on!
    >

    View full-size slide

  27. 30
    # app/services/purchaser.rb
    class Purchaser < ActiveService ::Base
    needs :payment_transaction
    needs :order_mailer
    def purchase!(customer:, card:, order:)
    transaction = payment_transaction.new(card,order.amount)
    if transaction.success?
    order_mailer.receipt_email(customer,order).deliver_later
    else
    order_mailer.card_failed(customer,order,transaction).deliver_later
    end
    end
    end
    # config/initializers/braintree.rb
    service :payment_transaction do
    Braintree ::Transaction.new(api_key: ENV["BRAINTREE_API_KEY"])
    end

    View full-size slide

  28. My Rails X
    Unbundled & Separated
    Environment-friendly
    More abstractions, less implementations
    (More) Developer happiness
    Scalable codebase
    For the web and beyond
    Modern
    32

    View full-size slide

  29. UNBUNDLED
    33
    Pieces of the puzzle must fit
    >

    View full-size slide

  30. Unbundled
    Upgrade individual parts
    Use sub-frameworks independently
    Avoid unneeded dependencies
    34

    View full-size slide

  31. 35
    >= 5.1
    -> nokogiri ( >= 1.6)
    actionpack (6.1.3.1)
    actionview (= 6.1.3.1)
    activesupport (= 6.1.3.1)
    rack ( ~> 2.0, >= 2.0.9)
    rack-test ( >= 0.6.3)
    rails-dom-testing ( ~> 2.0)
    rails-html-sanitizer ( ~> 1.0, >= 1.2.0)
    "actiondispatch"
    *

    View full-size slide

  32. ActionPack
    36
    Router
    🤯 *

    View full-size slide

  33. ENVIRONMENT
    38
    Stop polluting the environment
    >

    View full-size slide

  34. stop_core_ext_everywhere
    > 39

    View full-size slide

  35. ABSTRACTIONS VS.
    IMPLEMENTATIONS
    40
    Replace leaking implementations with non-leaking abstractions
    >

    View full-size slide

  36. Rails 3-4: Sprockets
    Rails 5: Sprockets + Webpacker
    Rails 6: Webpacker + Sprockets
    Rails 7: ???
    41

    View full-size slide

  37. If you can’t decide, ship with
    zero options instead of two!
    42

    View full-size slide

  38. 43
    Interfaces not implementations for the outside world dependencies
    >

    View full-size slide

  39. 44
    actiontrix

    View full-size slide

  40. DEVELOPER EXPERIENCE
    45
    Supporting tools are becoming more and more important than the language itself.–Matz
    >

    View full-size slide

  41. My typical Rails journey starts like this
    > 46

    View full-size slide

  42. DX
    Plug-n-play development environment
    47

    View full-size slide

  43. Shall we sail, too?
    > 49

    View full-size slide

  44. DX
    Plug-n-play development environment
    Quick setup for new projects
    50

    View full-size slide

  45. 51
    open https: //railsnew.io
    >

    View full-size slide

  46. Oh, it's aiready a year old!
    > 52

    View full-size slide

  47. DX
    Plug-n-play development environment
    Quick setup for new projects
    Project-specific generators
    53

    View full-size slide

  48. Generators
    Generator could only be useful if it fits your
    project needs
    Make a generator a part of the project
    Generate the generators!
    54

    View full-size slide

  49. DX
    Plug-n-play development environment
    Quick setup for new projects
    Project-specific generators
    55

    View full-size slide

  50. DX
    Plug-n-play development environment
    Quick setup for new projects
    Project-specific generators
    Deployment-ready
    56

    View full-size slide

  51. 57
    ActiveHeroku, ActionKubernetes, ActuallyCapistranoIsStillAlive ...
    >

    View full-size slide

  52. github.com/lewagon/seatrain
    58
    Under the sea, under the sea, darling, it's better, down where it's wetter
    >

    View full-size slide

  53. SCALABLE CODEBASE
    59
    Rails scales, and you?
    >

    View full-size slide

  54. 60
    The promise of the new bright future
    >

    View full-size slide

  55. MAJESTIC MONOLITH
    61
    We all want to build majestic monoliths and citadels ...
    >

    View full-size slide

  56. SHIT-ESTIC MONOLITH
    62
    But usually that turns out as ...
    >

    View full-size slide

  57. 63
    Cutting the application in slices 🔪
    >

    View full-size slide

  58. Modular architecture
    Engines should become an official way to extract
    components
    Engines must be supported by all sub-frameworks
    64

    View full-size slide

  59. Modular architecture
    Engines should become an official way to extract
    components
    Engines must be supported by all sub-frameworks
    Engines should just work!
    66

    View full-size slide

  60. 67
    github.com/palkan/engems
    One can dare to use engines today
    >

    View full-size slide

  61. Modular architecture
    Cross-component communication out-of-the-box
    68

    View full-size slide

  62. 69
    Did I show you enough reasons to choose PHP for the next project? 😄
    >

    View full-size slide

  63. engines/
    core/
    app/
    events/
    core/
    users/
    registered.rb
    chat/
    app/
    subscribers/
    core/
    users/
    on_registered/
    create_chat_account.rb
    github.com/palkan/active_event_store
    Event store the Rails way
    > 70

    View full-size slide

  64. BEYOND WEB
    71
    Can Rails break out of the Web world?
    >

    View full-size slide

  65. 72
    Server is a terrible abstraction (Daniel Azuma, RailsConf 2021)
    >

    View full-size slide

  66. Beyond Web 🚀
    HTTP server should be just one of the possible
    entry-points (e.g., gRPC, cables, serverless)
    Both request-response and events (streaming)
    based communication supported
    AbstractController should be really abstract!
    > 73

    View full-size slide

  67. MODERN
    74
    Is it 2021 or what?
    >

    View full-size slide

  68. Modern
    Ractor-ready
    Async-ready
    RBS-ready
    75

    View full-size slide

  69. 76
    github.com/pocke/rbs_rails
    Shouldn't Rails itself generate RBS for Rails 🤔
    >

    View full-size slide

  70. And a lot more...
    Improved instrumentation
    77

    View full-size slide

  71. 78
    Good company always worth the time
    >

    View full-size slide

  72. And a lot more...
    Improved instrumentation
    Improved testing tools (benchmarks, property-
    based, factories along with fixtures)
    Improved views
    79

    View full-size slide

  73. Views X
    Isolated (no instance vars leaking)
    Components-first (view_component)
    UI kits or alike
    80

    View full-size slide

  74. Improved instrumentation
    Improved testing tools (benchmarks, property-
    based, factories along with fixtures)
    Improved views
    Improved configuration (anyway_config)
    81
    And a lot more...

    View full-size slide

  75. And a lot more...
    Improved instrumentation
    Improved testing tools (benchmarks, property-
    based, factories along with fixtures)
    Improved views
    Improved configuration (anyway_config)
    Improved Rails commands
    82

    View full-size slide

  76. Full-features CLI instead of Rake
    Fast start time (no application loading)
    First-class support for custom commands
    83
    Rails Commands X

    View full-size slide

  77. INVARIANTS
    84
    Some things should never change
    >

    View full-size slide

  78. SIMPLE STAY SIMPLE
    85
    Blog in 5 minutes without DI, algebraic effects and monads ⏱
    >

    View full-size slide

  79. SAFETY FIRST
    86
    Make it hard to shoot yourself in the foot
    >

    View full-size slide

  80. AM I A DREAMER?
    87

    View full-size slide

  81. discuss.rubyonrails.org
    88
    Your journey starts here!
    >

    View full-size slide

  82. We are hiring. We are hiring. I am hiring. I am herring 🐟
    >
    evl.ms/jobs

    View full-size slide

  83. THANKS!
    90
    Exclusively for Saint-P Ruby Conf 2021 by Vladimir Dementyev, Evil Martians
    >

    View full-size slide

  84. DISCUSSION TIME
    91
    What do YOU want to fix in Rails?
    >

    View full-size slide