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. 1

    View Slide

  2. Vova on Rails, since 2014
    > 2

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  9. Rails X == Rails 🤔
    > 9

    View Slide

  10. Rails X == Hanami 😸
    > 10

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  16. 16

    View Slide

  17. EXTRACTIONS FEATURES
    17

    View Slide

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

    View Slide

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

    View Slide

  20. Dead weight detected ☠
    > 20

    View Slide

  21. SEPARATE ECOSYSTEM
    FROM FRAMEWORK
    21

    View Slide

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

    View Slide

  23. 23
    The student has surpassed the teacher (
    >

    View Slide

  24. Tender age in bloom 🌸
    > 24

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  29. 29

    View Slide

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

  31. 31

    View Slide

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

    View Slide

  33. UNBUNDLED
    33
    Pieces of the puzzle must fit
    >

    View Slide

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

    View Slide

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

  36. ActionPack
    36
    Router
    🤯 *

    View Slide

  37. 37
    🤔

    View Slide

  38. ENVIRONMENT
    38
    Stop polluting the environment
    >

    View Slide

  39. stop_core_ext_everywhere
    > 39

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  44. 44
    actiontrix

    View Slide

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

    View Slide

  46. My typical Rails journey starts like this
    > 46

    View Slide

  47. DX
    Plug-n-play development environment
    47

    View Slide

  48. 48

    View Slide

  49. Shall we sail, too?
    > 49

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  60. 60
    The promise of the new bright future
    >

    View Slide

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

    View Slide

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

    View Slide

  63. 63
    Cutting the application in slices 🔪
    >

    View Slide

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

    View Slide

  65. 65

    View Slide

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

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

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

    View Slide

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

  74. MODERN
    74
    Is it 2021 or what?
    >

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  78. 78
    Good company always worth the time
    >

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

  84. INVARIANTS
    84
    Some things should never change
    >

    View Slide

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

    View Slide

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

    View Slide

  87. AM I A DREAMER?
    87

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide