I only clicked through out of morbid curiosity: the software architecture version of watching a train wreck.
Even that seems weird to me. If want to load objects, I want to load them from a particular repository, not a class of repositories (which the upper-casing of `UsersRepository` suggests).
As soon as your app needs to talk to more than one data source, this business where data is tightly coupled to a particular datasource by the framework makes a big mess.
But that's why I don't use Rails in the first place.
Glad it’s satire.
"strive for overall system clarity as your principle pursuit
user.log_entries.delete_all
user.log_entries.create!(message: "User account reset")
user.log_entries #=> [], will be empty until reloaded
This is false. At least not in Rails 7+ (haven't tested earlier), user.log_entries will return exactly what you'd expect (one instance of LogEntry).Yes, it is a good idea to decouple your application from the framework. Yes, it is a good idea to write your own functions which wrap persistence layer library functions. Yes, it is a good idea to drive out the design of the system with automated tests, and to avoid having to test behaviour with more expensive integrated tests where possible.
The first phase was being amazed that we got basic functionality up and running so fast
The second phase was feeling like we were spinning our wheels because we were always dealing with some performance issue or some complexity explosion that occurred when we stepped outside of the bounds of a simple low volume CRUD app where Rails excels.
Complexity does not have to be an explosion, but it always will be if the team designs in a way that is not coherent - and coherence is hard to achieve.
"No build step for assets" is how I do my Rails apps these days if I can help it, luckily modern browsers allow for that to a great extent.
And yes, it is nicer to avoid expensive tests if you can help it. It has been my experience, however, that if you can use a slightly-more integrated test - which touches more parts of the system - you are likely to find more regressions and much quicker than if you subscribe to the notion of "testing one function with collaborators all around". It is academically very appealing, and your tests will be quite fast indeed - but they will be much harder to read and understand, and are always one "and_call_original" away from being useless.
As to decoupling from a framework in an ecosystem where, realistically, there is only one framework - and where, realistically, there are no deployment targets except for that framework - I don't believe this to be useful, sorry.
Yes, you can deploy your code into a cloud function (both AWS and GCP do Ruby cloud functions and you can get quite a bit of mileage out of it) but this is not an architecture you are likely to plan for - or need - until quite, quite late into the growth of a codebase. And even then - those runtimes have different constraints, so you may want to build a module which is accessible both from Rails and from such a cloud function.
What I don't like is the conversation of "you must decouple to decouple", which is not a way to advocate for something at all.
Also, none of this is specific to Rails. I have the same concerns with Yesod, although it's easier to get unstuck in the latter case because of the typechecker.
I don't know why would you replace AR to make a repository if you can build it on top of AR.
Maybe if the generation of those queries is from templates and it is the concern at hand - a better approach is using a restricted templating system like Liquid where all possible queries are canned and pre-generated via specific template helpers, but I doubt this mandates a Repository still.
Uhm...no? This is just about keeping things DRY. Do you pride yourself in writing an SQL query from scratch every time you need a query database? Abstracting `where()` and co away makes life easier for everyone to stay on the right path.
aaroninsf•6mo ago
https://sketchfab.com/3d-models/hexatetrahedron-a0ef716cd462...