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

RailsConf 2024: Riffing on Rails: sketch your way to better designed code

RailsConf 2024: Riffing on Rails: sketch your way to better designed code

Say you've been tasked with building a feature or subsystem in a Rails app. How do you get started? How do you plan out your objects? How do you figure out the names, responsibilities, and relationships? While some reach for pen & paper and others dive straight into implementation, there's a third option: Riffing on Rails.

When you riff, you work with Ruby code in a scratch file to help drive your design. This way you get rapid feedback and can revise as quickly as you had the idea — try out alternative implementations too! It's great for building shared understanding by pairing with a coworker.

Walk away with new ideas for improving your software making process: one where code is less daunting & precious. Riffing gives you space & grace to try more approaches & ideas. Let's riff!

Kasper Timm Hansen

May 07, 2024
Tweet

Other Decks in Programming

Transcript

  1. @@export_scripts@@ SPEAKER: Kasper Timm Hansen Speaker Bio: Kasper is an

    independent Rails consultant with a strong focus on clear naming and Domain Modeling. He used to be on the Rails core team where he reviewed & merged over 1000 contributor PRs. Kasper is still involved in Open Source with his own gems that take Rails further and he’s contracted for Bullet Train too, so he’s more than happy to talk about that work. He’s also developing a new software development technique called Riffing, that he’s amped to see how it could fit and level up you and your team’s process. ROOM: 140 E-G
  2. @@export_scripts@@ how it works - use a single Ruby file

    - lean on conventions as much as possible - use near runnable code
  3. @@export_scripts@@ # Users can favorite other objects in our system

    class User has_many :favorites def favorite(record) = favorites.create!(record:) end class User::Favorite belongs_to :user belongs_to :record, polymorphic: true end class Users::FavoritesController def create Current.user.favorite SignedGlobalID.find(params[:id], only: [Post, Comment], for: :user_favorites) end end
  4. @@export_scripts@@ One more thing: make it executable require "bundler/inline"; gemfile

    do gem "activerecord", require: "active_record" gem "sqlite3" end ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:" ActiveRecord::Base.logger = Logger.new STDOUT ActiveRecord::Schema.define do create_table :users create_table :posts do |t| t.references :user, null: false, index: true t.string :title, null: false end end class User < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :user end user = User.create! post = Post.create! user:, title: "First" binding.irb
  5. @@export_scripts@@ Taking Rails further active_record- associated_object active_job- performs … active_record-

    ingress action_controller- stashed_redirects Bullet Train nice_partials showcase-rails Experimental brb-templates hercule-poro