News for hackers. Stuff that matters.
Re:How to Build a Web App with and Without Rails Libraries by jack_riminton on Wednesday March 31, 2021 @03:35AM (#26644458)
This is how we learned Ruby at bootcamp. The problem was that once we got to the more complex Rails parts, the instructors didn't have the time to fully explain it so it was explained as "Magic, don't worry about it too much" which was extremely frustrating
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

Re:How to Build a Web App with and Without Rails Libraries by mhasbini on Wednesday March 31, 2021 @06:13AM (#26645440)
When I get a chance, I try to dig into the "magic" parts of the tools I'm using.

I've wrote a bit on this on my blog in the context of creating a (nano) web framework similar to Rails [1] and a (nano) http client library similar to requests [2].

I find this to help assure me that if I have to go one layer deep in abstraction I'd still be able to learn how it works.

[1] https://mhasbini.com/blog/lets-build-a-web-framework.html

[2] https://mhasbini.com/blog/lets-build-an-http-client.html

Re:How to Build a Web App with and Without Rails Libraries by ZephyrBlu on Wednesday March 31, 2021 @05:05AM (#26645012)
Realistically you generally won't have time to fully understand how most things work though.
Re:How to Build a Web App with and Without Rails Libraries by jack_riminton on Wednesday March 31, 2021 @05:20AM (#26645098)
I know, and accepting that frustration is part of becoming a developer, but there are others schools such as Lambda where you do go into more depth because its 9 months instead of 3
Re:How to Build a Web App with and Without Rails Libraries by eu on Wednesday March 31, 2021 @09:25AM (#26646960)
That's why I abandoned RoR early..