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

Who needs Rails in 2018?

Who needs Rails in 2018?

English version of my talk at Ruby Meditation #22

Leonid Shevtsov

May 19, 2018
Tweet

More Decks by Leonid Shevtsov

Other Decks in Programming

Transcript

  1. A polyglot's view of Ruby & Rails or "Who needs

    Rails in 2018" Leonid Shevtsov · Ruby Meditation · May 2018 · Dnipro
  2. Hello! My name is Leo and I'm not a fan

    of Ruby → Ten years ago I was enamoured by it
  3. Hello! My name is Leo and I'm not a fan

    of Ruby → Ten years ago I was enamoured by it → Six years ago I hated it
  4. Hello! My name is Leo and I'm not a fan

    of Ruby → Ten years ago I was enamoured by it → Six years ago I hated it → I searched far and wide for a replacement
  5. I searched far and wide for a replacement (that is

    so trendy, right?) → Scala → Clojure
  6. I searched far and wide for a replacement (that is

    so trendy, right?) → Scala → Clojure → Elixir
  7. I searched far and wide for a replacement (that is

    so trendy, right?) → Scala → Clojure → Elixir → Golang
  8. I searched far and wide for a replacement (that is

    so trendy, right?) → Scala → Clojure → Elixir → Golang → F#
  9. I searched far and wide for a replacement (that is

    so trendy, right?) → Scala → Clojure → Elixir → Golang → F# → Node.js
  10. Simplicity 1 # The famous Hello World # Program is

    trivial in # Ruby. Superfluous: # # * A "main" method # * Newline # * Semicolons # # Here is the Code: puts "Hello World!" 1 https://ruby-lang.org
  11. Pleasant, readable code 2 5.times { print "Odelay!" } exit

    unless "restaurant".include? "aura" ['toast', 'cheese', 'wine'].each { |food| print food.capitalize } 2 http://poignant.guide/book/chapter-3.html
  12. Living in Runtime class User < ApplicationRecord # поля???? end

    vs $> rails console > User.methods => [:id, :name, :email, ...]
  13. Rapid development $> heroku run rails console # Copy +

    Paste > class User def buggy_method # fixed implementation goes here end end > User.where(buggy: true).each(&:buggy_method)
  14. Simplicity + Conventions + Rapid development = Projects where logic

    and especially data structures are still unknown
  15. Ruby that I love is religiously Rubocopped Metrics: → line

    length → method length → module length → complexity → number of arguments
  16. Ruby that I love is well commented → monkeypatching →

    hacks → "...I would typically write XXX, but in this case I will write YYY..." → write that down as a comment!
  17. Ruby that I love → Rubocopped religiously → Structured into

    small modules → Uses dependency injection → Does not keep state → Simple tests (thanks to DI) → Does not use too much "patterns" → Does not use too much metaprogramming → Mutable code is isolated → Decisions are documented
  18. Rails that I love Has little code in the models

    → validation → life cycle → associations → scopes
  19. Rails that I love Has little code in controllers →

    input checking → output generation
  20. Rails that I love Has business logic in modules →

    Rails is only for HTTP and the database. → Apps are more complex than that. → Own your app/*!
  21. Rails that I love Isolated database access class User <

    ApplicationRecord has_many :posts has_one :latest_post, class_name: 'Post', -> { order('created_at DESC') } end User.limit(10).includes(:latest_post)
  22. Rails that I love → Has little code in the

    models → Has little code in controllers → Isolated database access → Has business logic in modules → Use React as a view → RSpec tests → Capybara+Chrome
  23. What would I like to see in Ruby → Auto

    formatting (a la Prettier) → Static typing (optional)