Keep your ActiveRecord models manageable the Rails way
updated almost 5 years ago; latest suggestion almost 5 years ago
Rails is brilliant! It makes it very easy and enjoyable to start a new project. However, as your application grows, you will eventually have to come off the Rails or your codebase will become completely unmanageable. Everyone knows that.
You'll need presenters and a service layer, including role and use-case objects. DCI will be great too or, alternatively, you can go Hexagonal. After all, the web is just a delivery mechanism, the database is a mere persistence strategy and, of course, Rails is a detail.
But… Wait a minute! Is that really true? Does the Rails way no longer work when your application becomes large? How is it, then, that Rails claims to be “optimised for sustainable productivity”?
In this talk, we'll revisit the patterns and conventions that Rails encourages. We'll push them to the limit and see how the maintainers of large Rails applications keep their models manageable without needing to derail. We'll also discuss the trade-offs of being on and off the Rails. And, maybe, you'll finally learn how to stop worrying and love the Rails way!
Do you think that Concerns (e.g. mixin modules) are a first step towards actually breaking our models up? The tradeoff that Andrew describes where the full definition of our model is split across multiple files is maybe a secret push towards this as it makes us think "Oh! This model does a lot and it's hard to find" and one response to that is to push it further and actually have new objects that do the concern stuff instead (the other response is to just stuff it all back in one file).
Of course, I'm assuming that you think splitting models up is a good thing, maybe you don't. I'd be interested to hear you discuss something along those lines (no matter your opinion).
I think it doesn't go against the anonymous policy to say that I'm the author of these three proposals (which are variations on the same subject):
- Sustainable productivity: Rails vs OOP
- Keep your ActiveRecord models manageable the Rails way
- Patterns to deal with big ActiveRecord models
During the last six months I've been researching about the big-models issue in Rails. There's a fair amount of buzz in the community about how to deal with this problem and I thought it would be interesting to study in depth each different view.
James: This talk won't be necessarily a refutation of anything but rather a exploration of the "Rails way" as a sustainable approach in complex applications. And, yes, I plan to show some representative examples.
Andrew: Concerns will definitely be part of the talk and, as with the other patterns I'll present, I plan to discuss the trade offs of applying them in different scenarios.
Thanks for your input, guys!
I don't whether you're planning to use the idea of "concerns" (an idea that DHH has put forward as a response to DCI, etc.) but one problem with this approach is that you can easily end up with a model's definition spread across multiple files and developers unfamiliar with the codebase can find it hard to track where the implementation of a method is. It might be good to show how and when it could be used and when it shouldn't be.
It seems like there is some crossover between this talk and this one about patterns for large AR models. Do you think you can explain why your talk is different to that one, to help people decide when voting.
We could also put you in touch with the other proposer to work out what cross-over there might be, and potentially work the two talks into one?
Is it fair to say that this presentation is a refutation of some of the "DCI" or "OO" directions that some Rails developers are trying to move towards? Am I right in surmising that your basic argument is that Rails does provide mechanisms to manage complexity? If so, that could be interesting.
I'm assuming that you'll be drawing on some experience of a long-lived Rails application; if that's the case, it'd be useful to know the "scale" of this app - in terms of number of models, age, that sort of thing.