News for hackers. Stuff that matters.
Re:How to Build a Web App with and Without Rails Libraries by Toutouxc on Wednesday March 31, 2021 @05:24AM (#26645121)
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.
Re:How to Build a Web App with and Without Rails Libraries by blacktriangle on Wednesday March 31, 2021 @08:54AM (#26646623)
Agreed, 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.
Re:How to Build a Web App with and Without Rails Libraries by TheRealDunkirk on Wednesday March 31, 2021 @12:33PM (#26649361)
As a huge Rails fan... I wish I could refute this. ;-)
Re:How to Build a Web App with and Without Rails Libraries by skrtskrt on Wednesday March 31, 2021 @12:17PM (#26649140)
same with Django
Re:How to Build a Web App with and Without Rails Libraries by travisgriggs on Wednesday March 31, 2021 @10:24AM (#26647716)
Sounds like dark magic.
Re:How to Build a Web App with and Without Rails Libraries by chrisseaton on Wednesday March 31, 2021 @05:46AM (#26645266)
> 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?

Re:How to Build a Web App with and Without Rails Libraries by flippinburgers on Wednesday March 31, 2021 @07:23AM (#26645856)
Yes and it makes moving through any non-trivial rails codebase a total drag.
Re:How to Build a Web App with and Without Rails Libraries by blacktriangle on Wednesday March 31, 2021 @02:02PM (#26650714)
In 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.

Re:How to Build a Web App with and Without Rails Libraries by pantulis on Wednesday March 31, 2021 @07:13AM (#26645785)
Yes, 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.
Re:How to Build a Web App with and Without Rails Libraries by chrisseaton on Wednesday March 31, 2021 @07:21AM (#26645838)
I 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.
Re:How to Build a Web App with and Without Rails Libraries by toomanybeersies on Wednesday March 31, 2021 @11:47AM (#26648744)
Yea, but the documentation of said metaprogramming is generally quite comprehensive (with some exceptions).
Re:How to Build a Web App with and Without Rails Libraries by jac241 on Wednesday March 31, 2021 @05:34AM (#26645189)
I 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.
Re:How to Build a Web App with and Without Rails Libraries by toomanybeersies on Wednesday March 31, 2021 @12:20PM (#26649185)
I'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.

Re:How to Build a Web App with and Without Rails Libraries by nijave on Wednesday March 31, 2021 @10:22PM (#26655942)
Of 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