6 ms·
The Magic of Rails: exploring the principles and techniques behind the framework
- eximius 4y agoLike any good magic trick, it's an illusion. While you're looking over here, I've secretly built an unmaintainable monolith! Tada!
- jeremymcanally 4y agoSounds like you need to hire better magicians. :)
- rtheunissen 4y agoA framework is no good if it requires that the engineers working with it are excellent in order to not create a mess. A great framework or language _should_ empower participants with average ability and experience to produce good results.
- joshmn 4y agoI think the problem is a little more subtle. With Rails, you can call `relation.map(&:id)` and `relation.pluck(:id)` and get the same thing — an array of `id`. But using map is 50x slower because it loads the entire model into memory (ActiveModel is very expensive) before enumerating; pluck fires a query and hits the result set from ActiveRecord — very inexpensive! Average ability participants then fall for this foot gun (and others like it) and end up designing things poorly. One overlook quickly turns into accelerant at scale. This isn't unique to Rails, but Ruby — the delight that it is — makes it almost too trivial to do. I've seen this happen at Rails shops many of us have an account on, where I wouldn't consider the people I worked with average ability participants either.
- Sivart13 4y agoBut if you’re going to render those `relation` records in a paginated list anyway, pulling them into memory is superior so you don’t hit another DB round trip delay. Which is to say, there’s a lot of ways to do things, and trade offs between the different ways, but isn’t that the case with any library or framework?
- joshmn 4y ago> But if you’re going to render Sure – if – that's fine and optimal! In larger apps, where there's more complexity, there are so many paths that aren't that trivial and that's where the trouble begins.
- gls2ro 4y agoI dont understand how come a framework will help you avoid that. You can do a similar performance issue with anything: here is a raw example: give to anyone a non-ORM framework and the chances of someone hitting multiple times the DB to query the same records increases with team size and app scope. I am not sure there is a framework that can protect your colleagues from doing select * and then count the in memory objects instead of doing a count on DB.
- dasil003 4y agoWhat's an example of a framework that meets this bar? In my experience, the messiness is generally a function of scope, team size and technical ability. Some languages / frameworks give you better or worse tools for managing that scalability, but context matters (right tool for the job) and none can guarantee a good result if the team is weak. What really matters is the technical leadership, who must have both the experience, and sufficient influence, to avoid going down a path of crippling technical debt that eventually strangles the system. As far as Rails goes, for all it's shortcomings, people forget what web development was like in 2003. The dominant paradigms were overwrought XML-powered J2EE with incredibly low power-to-weight ratio for web development, or unstructured PHP wild west stuff. These days every language has a framework that was heavily influenced (directly or indirectly) by Rails. Sure I wouldn't use Rails everywhere (1000+ engineer team: java, lots of concurrency: elixir/erlang, lower-level large systems: go/rust, etc), but it still has a great sweet spot from the prototype to moderate sized web app / API. Things that become weaknesses as you scale (eg. ActiveRecord pattern) are based on contextual tradeoffs that need to be made thoughtfully versus declaring them table stakes for all web frameworks.
- nasmorn 4y agoAs if micro services are inherently maintainable. Those are really orthogonal categories
- ecshafer 4y agoMost "microservice" implementations I have seen are just monoliths spread out over many computers. I think breaking services up has a place, but I also think its vastly overdone and the hits to developer productivity, logging ability, are real.
- eximius 4y agoPersonally I advocate for modular monoliths with the boundaries set by gRPC services. Monoliths are fun to bash, but I'd rather have a monolith than poorly done microservices. The problem is that Ruby encourages (or, perhaps, doesn't discourage) a certain kind of tangled monolith.
- joshmn 4y agoI have been working with Rails for the last forever. I love Ruby, and I love Rails. Part of the reason why I love Rails so much is in slide 9: "Rails is designed to have agnostic interfaces." One of the reasons why I hate Rails is the steep learning curve. It's really easy to get something out the door with Rails. Whether or not it's maintainable long-term is what's up for debate. There are often 10 ways to get the same result: 1-5 are really bad, 6 and 7 are acceptable, 8 is good, 9 is great, 10 is perfect. Not everything has to be 10, or even 9, or even 8; the fewer 1-5s you have the better. The official "Getting Started" guides don't help this at all. Granted, they are indeed marketed correctly: they are for getting started. But it lends to this idea that that all Rails applications have to look that way — the "getting started" way. Many of my applications (and many of the shops I'm brought in to "better") end up shipping with more than what comes out of the box. This might sound normal to folk on HN — engineers are supposed to engineer things, after all — but it's lost on many teams and orgs. ("Many teams and orgs" are largely teams and orgs we have never heard about, and there are plenty of them.) Taking a peak at my usual interface stack includes commands, components, decorators, forms, inputs, queries, presenters, serializers, and services. This is in addition to the default controllers, helpers, mailers, models, views. My ultimate takeaway from seeing over a two dozen "this Rails app is painful to use" situations in the last two years is that the developers hadn't extended past the original patterns that were given to them when they originally spun up the app. This largely results in losing a lot of the Rails magic because developers are (unintentionally wrongfully) forced to do things that goes against Rails' expectations. There are other things besides shipping better abstractions too, obviously. The one that stands out the most is controllers doing too much and becoming God controllers; developers get lazy (or just aren't aware) and simply define routes that are RESTful in the router, but aren't in the actual controller definition. This makes for a tangled mess. There's a way to make Rails as much of a joy to use as it is when you first hit `rails new` — it just takes some experience and diligence. That can be said for every framework. But what can't be said for every other framework is that Rails makes it way too easy to write really bad Ruby code that, ultimately, gets you the "right" result. Avoiding those is the hard part. (I'm currently looking for work in case anyone wants to talk)
- rtheunissen 4y agoReplace Rails with Laravel and you get the same problem: the recommended patterns make it easy to get started but eventually work against you when things start getting big and busy.
- ulizzle 4y agoThe problems with Rails are the same as with Ruby as it was with Smalltalk: just too easy to make a mess (the nature of dynamic languages), and its community suffers from a nasty case of groupthink. Notice the cliche "Rails is so much more than a framework." The same magic that makes one so productive at the beginning (start-up stage) is what comes back to bite you in the ass when the project grows into an actual product; unless you are careful and willing to trade off speed-to-market, which isn't what you want to do with a startup. Catch-22 because the app has gone off the rails by the time you are successful, and everyone says: "Oh, you shouldn't have done that."
- lawn 4y agoIncidentally I feel Rust is the reverse Ruby: more work (sometimes much more work) up front, but the big payoff comes in the long run.
- ulizzle 4y agoMany typed languages are like that, but the big difference is that they admit the trade-off. In Ruby on Rails, dissent is a big taboo, so they blame the problems on the devs (the unwashed nameless masses) rather than tackle the problem itself. That's why you have all these different tools and concepts; since they try to sandpaper over all the magical complexity by adding more complexity, it becomes a no-true Scotsman trivia game. What trips me up tbh is how tech history repeats itself almost verbatim. The Smalltalk story is very similar but with a different cast.
- rileyphone 4y agoIn what way is Smalltalk similar? Its main problem was that it stopped evolving.
- namaria 4y agoAll software suffers from this. The whole point of programmable computers is allowing systems of unbounded complexity. Every tooling discussion degenerates into "it's a foot gun" vs "you're holding it wrong". If you remove friction, people will build bigger foot guns. If you install too many guardrails, holding it right requires contortion. The point is not which set of tools you use. There is no substitute for understanding the problem domain, the tools at hand and the labor market you have access to. Everything has a cost, you can't get free advantages from some technical insight or another.
- nathants 4y agoit’s like the t-shirt from happy gilmore: guns don’t kill people, i kill people. for whatever reasons, rails became easy to discover and use. that so many ended up committing git based crimes with it is not rails fault. personally i blame education and media. we can do better.
- deleted 4y ago[deleted]
- dlisboa 4y agoI've been a Rails dev for many, many years, so I'm not shitting on it. My one concern with Rails is human scaling, not so much "web scaling". A lot of big companies use Rails and are successful at a large human scale. But one thing that is often not talked about is that they have the financial resources to hire the very best programmers in the world, and often they hire the very people who build the framework (e.g. Shopify, GitHub I think had a few members go through it, etc). This is critical when the biggest questions with Rails is: how to achieve clean code, modularity and separation of concerns; how to achieve high throughput. It doesn't surprise me that Basecamp says they never have issues with a huge monolith in Rails: they invented the framework and know their way around it. It doesn't surprise me that Shopify doesn't have issues with scalability: they have Rails core team members and Ruby engineers dedicated to creating an entire new Ruby VM. If the problems with Rails are solved by "throw the best people in the world at it" then it's a self-limited proposition. I have worked on countless Rails apps over the years, not one would pass the "this is just great code" test. They were not built by incompetent programmers. It's just that the "Rails way" needs a very heavy guiding hand behind it. In the real world that is often easy to lose: senior team members leave, you don't have time to rewrite parts of the code, you may not even have the expertise in-house to improve the codebase significantly. Bigger companies don't usually have these problems. And if you look at big Open Source Rails projects (Discourse, Spree, Gitlab), you'll often see the same patterns: 1000+ line models, non-standard Rails-way ideas like services and operators, hundreds of files all in the same place without any clear modularity... and these are not bad programmers at all. Maybe Rails at human scale is just hard, or maybe there’s something about the framework that leads to this.
- devoutsalsa 4y agoFor some reason, Rails is the only framework I’ve worked with that seems to require constant discussions about design patterns and best practices. I don’t know why.
- notjoemama 4y agoInteresting. I worked on a team for several years and our discussions were completely absent of design patterns and best practices. I'm older. Do you think age/experience plays into it? I only ask because I'm not interested in those discussions anymore because I feel like I've already had them all.
- jkmcf 4y agoThe biggest problem with any language, be it Ruby, Java, or C is founder code written by language ignorant coders who don't learn the language and relevant idioms. The good thing is there's value delivered quickly essential to growing the company, but amounts to a lot tech debt and human scaling problems a few years later.
- notjoemama 4y agoI'm giving up on this discussion. I see plenty of critique of Rails but they're obtuse statements that could apply to any app framework. Oh, rails causes devs to make a mess at scale? Huh, well let me introduce you to my friend React. Unless you say something specific, then you're doing twitter-like pile on and nothing of substance is being added by your voice. Here's my critique of rails that offers specifics. There are parts of the framework that are automatically baked in but unknown and unused by the majority of projects. Message encryptor comes to mind. I'd prefer to choose a feature set, like a toggle config. Why should my company pay for objects to reside in memory that have never and will never be used? Or how about the need to duplicate directory structure within M, V, and/or C? Kinda exhausting and boring. It doesn't take long until the question arises, why does it have to be that way? Oh, well, of course it doesn't. But if you're doing it "the rails way" where its convention over configuration then it should be done. Not to mention well known widely used rubygems rely on following the convention withing your own app. I'm not saying its bad, but its boilerplate the generators currently don't handle. Aside from rails, I see alot more complexity added, not by rails or follwong rails convention, but by adhd bored devs that play social games, that are a weird mix of "I'm better than you" and "I'm tragically insecure of you finding out I'm not as so smart". I'll take a team of middling hard working devs over a 10xer on the spectrum any day.
- ulizzle 4y agoFunny enough, we just had a post on the front page here in HN from a rails conf organizer saying that rails confs are the epitome of adhd bored devs playing a social game of “im better than you” and “I’m tragically insecure of you finding out I’m not so smart” Spooky.
- notjoemama 4y agoYeah. I didn't see that. Any chance you can link which one you're referring to? Are you saying the phrasing I just used matched verbatim?