4 ms·
I believe we should really dial down the usage of the word "magic". There are some parts of Rails that feel "magical" as in "surprisingly easy to use" or "very
by Toutouxc 6y ago
I believe we should really dial down the usage of the word "magic". There are some parts of Rails that feel "magical" as in "surprisingly easy to use" or "very convenient", but it's nothing like "magic that nobody understands". You can always read the actual implementation in your IDE, and Rails code is nice and readable with comments and examples. It's just as easy or difficult to reason about as other complex codebases. I don't remember myself ever hitting a wall and still not understanding what's going on two hours later.
- jac241 6y agoI am with you on this. What's magical in Rails? It imports classes for you by name based on their file path, "resources" routes to one of seven methods, templates are expected to be in a directory and named based on controller name and action, it defines methods on models for you based on the column names in the database, it runs files you you put in the initializers directory. All of this stuff is convenient, gets rid of boilerplate, and isn't hard to understand.
- deleted 6y ago[deleted]
- toomanybeersies 6y agoI've been a Rails developer for half a decade now, and I wish I had the time to list all the occasions where I've just about thrown my MacBook out of the window trying to do something that Rails wasn't specifically built to do, or been shot in the foot by ActiveRecord trying to be too smart for its own good. Solving autoloading problems is always a favourite too. I enjoy using Rails, but sometimes it's a pain in the ass, and usually because it tries to be too clever to reduce the amount of boiler platey code you need to write. In terms of code management, I'd much rather have explicit dependencies. Less `belongs_to :thing`, and more `belongs_to :thing, foreign_key: 'thing_id', klass: Thing`. Makes refactoring and code navigation so much easier. Also, pre-Rails 5, the defaults for DB migrations and relations were trash.
- nijave 6y agoOf course it no longer seems magical when you understand the implementation. The issue is understanding the application without working your way up from the inner bowels of Rails source. Things auto running and importing themselves seems magical because no other mainstream language does that
- chrisseaton 6y ago> You can always read the actual implementation in your IDE Doesn't Rail's use of metaprogramming mean that often there isn't a simple static implementation of a method in the source code that you can go and find?
- pantulis 6y agoYes, but it just implies that you cannot rely on grepping the source code. You know the relevant "method_missing" implementation is somewhere, and you can make an educated guess as where to look for it.
- chrisseaton 6y agoI think I’m pretty well informed about Ruby metaprogramming but I still really struggle to read through the magic sometimes. I can appreciate it’s somewhat impenetrable to beginners.
- Dirlewanger 6y agoSure, but who the hell's going to read that, honestly? All the metaprogramming crap was my biggest hurdle when learning Ruby/Rails at the same time, and also figuring out what was Ruby and what was Rails. Rails actually does a great job of naturally extending Ruby so much that most of the helper modules in activesupport feel native. Also, Rails has top-tier documentation, including listing out all the dynamic methods for each database field.
- flippinburgers 6y agoYes and it makes moving through any non-trivial rails codebase a total drag.
- toomanybeersies 6y agoYea, but the documentation of said metaprogramming is generally quite comprehensive (with some exceptions).
- blacktriangle 6y agoIn fairness they've been moving away from a lot of those methods. For example the whole find_by_<attr_name> dynamic methods have been replaced with find_by(attr_name: value). And while you can't find the method code itself, for example the generated code to access a has_many relationship, you can pretty easily find the meta programming that will generate it by following the class method name.
- blacktriangle 6y agoAgreed, rather than magic we should call it what it really is: a massive amount of introspection on the name of things creating implicit interfaces that reach across layers of the application resulting in some of the nastiest, brittlest, most highly coupled code you will ever write.
- travisgriggs 6y agoSounds like dark magic.
- skrtskrt 6y agosame with Django
- TheRealDunkirk 6y agoAs a huge Rails fan... I wish I could refute this. ;-)