5 ms·
Ruby's metaprogramming allows you to create really nice, ergonomic abstractions. I can write `has_one :posts` in a User model class in Rails and a ton of usefu
by fishtoaster 3y ago
Ruby's metaprogramming allows you to create really nice, ergonomic abstractions. I can write `has_one :posts` in a User model class in Rails and a ton of useful functionality pops into existence.
On the other hand, that deep magic metaprogramming can be really hard to follow if you need to understand how it works. Tracing back through (or even debugging) a metaprogramming-heavy codebase is a nightmare.
I'd argue that deep magic metaprogramming is great for when you have abstractions you almost never need to dig into. Rails is great because it's relatively rare that I need to go spelunking in the rails codebase itself (and thus understand the deep magic). Instead, I can rely on a huge pile of documentation, stack overflow answers, conference talks, etc to figure out how to use rails' abstractions (like `has_one :posts`) without needing to understand their implementation.
On the other hand, the average production codebase should minimize their use of metaprogramming. When I don't understand how Joe's `Whatsit` interface works, I'm much more likely to need to dig into Joe's code to understand how to use that abstraction. If I have to understand Joe's deep magic every time I do that, it's a net loss.
- hiharryhere 3y agoIt’s not even has_one :posts, it’s has_one :post because of even more rails pluralization magic :) Agree with everything you said
- rezonant 3y agocould be a model called Posts and plural is "postses" :-) (disclaimer: I do rails all day)
- nightpool 3y agofor debugging, I can't recommend pry (and pry-byebug for older pre-Ruby 3 codebases) heavily enough. being able to do show-source post.author and have it automatically unwind all of the metaprogramming and magic is really helpful
- LapsangGuzzler 3y agoThe new Ruby debug module is even better than pry. It has all of the step-into, step-out-out, object inspection, etc. featuring I’ve ever wanted.
- nightpool 3y agoI haven't gotten a chance to try it yet! definitely looking forward to it after we figure out the whole keyword arguments nightmare :)
- peteforde 3y agoOn the topic, I urge you to check out https://rubyjard.org/ https://rubyjard.org/ I have never looked back.
- shaicoleman 3y agoUnfortunately it seems like it's not maintained anymore
- peteforde 3y agoI'm in touch with the author, and he is responsive to concerns. Jard is a tool that is simply done/complete/ready. JavaScript as a developer culture seems to have convinced a lot of folks that if a package isn't updated at least a few times a year, it's "dead".
- fishtoaster 3y agoPeople do like to blame this on JS, but it's been true as long as I've been writing software. "Don't build on unmaintained libraries" was a lesson I learned hard in Ruby, long before the javascript ecosystem was a thing. RubyJard looks cool, but the repo is marked as "Archived" and the last commit predates Ruby 3. And, in fact, it looks like there are issues with Ruby 3.2 and RubyJard. Most software cannot really ever be "done", if only because no software operates in a vacuum. Nearly all software relies on a language, a standard library, an OS, direct dependencies, indirect dependencies, etc. The only way your software can be "done" is if it relies on absolutely nothing, and very little useful software does that.
- deleted 3y ago[deleted]