4 ms·
I started my professional career with Rails 8 years ago and deeply miss aspects of it. It uses lines of code so efficiently, letting you go from zero to product
by sickcodebruh 3y ago
I started my professional career with Rails 8 years ago and deeply miss aspects of it. It uses lines of code so efficiently, letting you go from zero to product with outrageous speed. Everything is a solved problem. Ruby as a language is so expressive, so beautifully ergonomic, so easy to read. It's such a joy.
But the view layer has not aged well. After years of working with a focus on React and TypeScript, I can't stomach the Rails approach to views. As much as I appreciate the value proposition of Stimulus and truly feel the shortcomings of SPAs deep in my bones, I crave components, type safety, unidirectional data flow, and more options for styling than just classes. React in particular has rich options for UI frameworks that feel truly idiomatic. The last time I tried to start a project with Rails, I moved at a breakneck pace until I got to the view layer, at which point I had to pull the plug.
I'm reaching for Next.js these days because it's the closest I can get. It gives me the opinionated framework I crave plus server rendering and the ability to drop down into client-side rendering when it calls for it. Prisma is a damn good ORM, even if it doesn't have the intuitively ergonomic beauty of ActiveRecord. And of course, TypeScript throughout is a godsend.
But I still miss Rails. I miss the console, Sidekiq, the profound power of ActiveRecord for simple things with the ease of dropping back into SQL when I need it, the polish of FactoryBot and those easy easy easy tests. I miss the breezy and fluid syntax of Ruby. I don't feel limited by TypeScript, I love working with it, but TypeScript lets me lecture, Ruby lets me sing.
- gedy 3y ago> But the view layer has not aged well. Agreed - In my opinion, Rails messaging/soft marketing could be a lot better about how it's great for a data driven backend, whatever the frontend/UI. I know there's things like API mode and webpacker, but this all seems very secondary and begrudging at times. Maybe I listen too much to what DHH says, but definitely think the Rails view stuff should be what's secondary. It's a turnoff for a lot of devs who would otherwise be quite happy with Rails as a backend.
- sickcodebruh 3y agoI dunno, I think that there are a lot of products and developers who need the view to be as important as the backend, and it would be a shame for Rails to stop trying to woo them. Rails is making a big push for Hotwire (https://hotwired.dev/ https://hotwired.dev/) and on paper, it certainly looks like a very Rails-y way of doing views. Elixir users seem obsessed with LiveView and this seems cut from the same cloth, so maybe it’s the answer? But for it to be compelling for folks like me, it needs to be a bit more React-y: components with well-defined, type-safe interfaces, unidirectional data flow.
- simonbarker87 3y agoI never learned RoR, it’s had been perpetually number 3 on my “to learn” list for over a decade. However I loved CodeIgniter and also crave that all in one-ness so find myself going to NextJS time and time again now for that reason. I pair Next with Nest (sigh, why only one letter different?) when I need a proper backend but I can get so far with Next that I’m using it less and less now.
- silasb 3y agoViewComponent, from Github makes writing views much better, but it's far from perfect.
- sickcodebruh 3y agoNever seen this before, it looks great! I wonder how well it handles Sorbet or RBS types. Any experience with it? What makes it far from perfect?
- aledalgrande 3y agoHave you use the whole Hotwire suite? It's much better than just Stimulus. Componentizing your views will also make it more modern.
- sickcodebruh 3y agoI have not, no. When you say “componentizing”, what does that entail? Is it the ViewComponents gem? If someone reading this has experience with both TS+React and modern Hotwire apps, you’d do the world a service by writing a blog about modern Rails views for the experienced React developer.
- aledalgrande 3y agoYeah what I'm suggesting is a React-y modular view codebase. You can use ViewComponents but I quickly found it was too limited for me and I didn't like to have many files for a single component. I just use Rails partials, the performance hit for my app is none. I also wrote a local VSCode plugin for snippets autocomplete so I can go faster. Also sprinkle some (rare) Stimulus and Turbo streams/frames. The one thing you're gonna be missing is typing, Sorbet does not work in views.