News for hackers. Stuff that matters.
Re:From Node to Ruby on Rails by jstummbillig on Thursday December 16, 2021 @02:15PM (#29582505)
I never really understood the criticism about "magic" in Rails.

We are surrounded by magic (which only means things we can not realistically be bothered to take the time to really understand, in contrast to things which are incomprehensible). I have no real clue why the terminal works. I have no real clue why my OS works. I have no real idea how TCP/IP does its thing. Sure, I can use them – but I couldn't really explain and much less recreate them.

What I need in all the above is replicability. I do x, and I know y is going to happen. Get x, do y. This is true in Rails.

If I really wanna know more Rails is open and easily explorable. No one is preventing me from finding out how any piece of the "magic" works.

"Magic" class inheritance is a thing in JS as much as it is in Rails.

What is so special about Rails and "magic"?

Re:From Node to Ruby on Rails by horsawlarway on Thursday December 16, 2021 @07:15PM (#29585916)
> I never really understood the criticism about "magic" in Rails.

I'll state my case as clearly as possible: The magic in Rails REQUIRES memorization... freaking everywhere. And it provides virtually no hints to jog your memory.

There's just too much tooling, hidden away out of sight, and applied through shenanigans with Ruby that other languages/frameworks make MUCH more obvious.

Simple trivial example? Rails fucks with imports left and right. Rails allows you to not even write a require statement half the time - it's just going to load things from places. Hope you have that list memorized.

Does it save you some time? Yes.

Does it make the code look "Cleaner"? Sure.

Does it make my life a fucking chore every time I have to run a damn console to find the source location of an object at runtime because it's entirely unintuitive about where it freaking came from? Damn right it does.

---

If you started early in your career with Rails - you probably don't notice this. But if you have experience with a solid selection of languages (ex professionally I've used: GoLang, C, C++, JS/Typescript, C#, Java, Netlogo, Rust & Ruby) I find the discoverability in Ruby/Rails about the lowest on the list.

Very fast to work with if you happen to have it all memorized. But that's about the only compliment I can give it.

Re:From Node to Ruby on Rails by saghm on Sunday December 19, 2021 @12:53AM (#29611741)
> GoLang, C, C++, JS/Typescript, C#, Java, Netlogo, Rust & Ruby) I find the discoverability in Ruby/Rails about the lowest on the list

What's interesting to me about this comment is that among the languages I'm familiar with that you list, the difference between the best discoverability and the worst feels way larger than the difference between the worst one and Ruby. To me, C is barely any better than Ruby; sure, Ruby lets you define methods/types at runtime, but C doesn't even _have_ methods, making finding all the things you can do with a given type way worse in my opinion. Plus, you can still have some wonky generated stuff with macros, although I'll concede that's usually less common than Ruby metaprogramming. Java, C++, and Go are a bit better, since you get a namespace instead of just a random identifier without context, but these namespaces are generally split across multiple files, so in practice I would need to rely on tooling to do this for me, and at least with RubyMine this wasn't in practice _that_ much worse.

Re:From Node to Ruby on Rails by horsawlarway on Sunday December 19, 2021 @12:01PM (#29615668)
Don't get me wrong - there are definitely some C/C++ codebases where the macros have gotten way out of hand. But in general, they're both typed - which helps SO freaking much.

Ex: C doesn't have methods, but if you store most of your data in structs then you can easily do two things:

1) find all the places where the header defining that struct is included

2) Do a global search for the struct name

Both will present you with a nice list of places that data is used, and show the functions that accept it as an argument.

Where as with Ruby - I basically have to use RubyMine to get anything even sort of working, and even then it chugs along very slowly trying to do it. Solargraph in VSCode doesn't really work at all (at least 50% of the time it finds no definition for me) and just using a basic editor is a nightmare. Sometimes you can do a global find for "def [classname]" but that only gives you the definition, not any of the places that use/modify it.

Basically - Ruby is one of the few languages where I feel like global search just doesn't work well, and it also eschews import/require/include statements when used in Rails. It's just a tangled mess, and there's NO way to unwind it without tooling, and even the tooling struggles (RubyMine is a guaranteed way to get my fans running at full speed for large projects, and it's the best I've used).

Re:From Node to Ruby on Rails by svachalek on Friday December 17, 2021 @06:09PM (#29599451)
I have to work with a lot of legacy codebases day to day, but generally it's get in, figure it out, make a change, test it, and go. With Rails, I just end up in that "figure it out" loop over and over.

In my book it's a write-only coding environment like everyone used to complain about with Perl and PHP. People crank that stuff out really fast and move on and leave future generations to suffer. But they love it, of course.

Re:From Node to Ruby on Rails by montblanc on Saturday December 18, 2021 @01:08PM (#29606829)
How much effort did you put into learning Ruby and Rails properly? It's easy to get started but rather hard to master and it sounds like you're invested in other tech.
Re:From Node to Ruby on Rails by horsawlarway on Sunday December 19, 2021 @12:17PM (#29615838)
Right back at ya: "Which version of Ruby and Rails?" :P

Because to me - RoR is in the death spiral period that the original ASP.Net was in before Microsoft threw the whole thing out and started over with the Core version.

Namely: Rails trys to give you opinionated best defaults, but the "best defaults" have changed dramatically since the framework came into existence. So you end up with 6 very different set of opinions as the framework has evolved, and the documentation is poor (honestly, at least ASP.net had okish docs - I find Rails docs pretty damn bad) and you get a complete wash on 3rd party sites trying to find relevant info for the version you happen to be using.

Also - Unlike MS and ASP, Rails doesn't even fucking try to keep naming consistent. They seem to favor making the syntax as close to natural language as possible, often deprecating the old syntax in favor of new method names solely "because it reads better". Which drives me freaking nuts.

Inertia will keep it running for a long time, but it's not the thing I would pick for greenfield projects anymore.

Re:From Node to Ruby on Rails by montblanc on Sunday December 19, 2021 @11:30PM (#29621597)
I'll take legacy Rails over legacy Java or legacy PHP or legacy .NET but to each his own. Good luck!
Re:From Node to Ruby on Rails by nomilk on Saturday December 18, 2021 @03:42AM (#29602918)
Some random thoughts:

1.

These are fair criticisms. These kinds of problems can also be difficult to demonstrate to others who may help.

For example "some function `f(x)` gives 5 when it should give 7" will get an answer in 5 minutes on stack overflow, whereas "my thing's not working and I don't know why" will receive 4 downvotes and no answer in the same time.

2.

I tend to be the kind of learner who doesn't sit down for 30 days and read the docs cover to cover, but rather I start using the new tool on day 1 and figure out what I need to know as a I go. But rails rewards the former approach (i.e. reading through the rails guides - or even just skimming them). This may take a few weeks, but it gives the ability to at least know where to start to look if something has gone wrong.

3.

> And it provides virtually no hints to jog your memory.

I kinda agree. I feel like this should be easily addressed (although I'm not totally sure how).

Re:From Node to Ruby on Rails by onehair on Thursday December 16, 2021 @02:35PM (#29582736)
When multiple teams work on the same rails project, you're bound to have someone enhance some class somewhere, and all of a sudden, your isolated class is doing things it's not supposed to do, or at least you think it's not supposed to be doing it. You try to debug it, but there are no types no way for the tools you're using to let you know easily, here is where this specific piece of logic coming from.

In Typescript, entities have types and when you misuse something the typescript checker tells you while you're coding why, that's not what you're supposed to do. You can super easily track down the type and navigate the code base to the source and adapt either your code or edit the source. Easily. With rails, you're often required to do mental gymnastics to debug simple things, after the fact

Re:From Node to Ruby on Rails by montblanc on Saturday December 18, 2021 @01:11PM (#29606859)
> When multiple teams work on the same rails project, you're bound to have someone enhance some class somewhere

It really isn't that common just like it isn't that common to do it in JS or in Python. Some people used to do that shit a decade ago, it became frowned upon and I don't really see it anymore.

Re:From Node to Ruby on Rails by LargeWu on Thursday December 16, 2021 @02:55PM (#29583047)
Let's not pretend javascript Promises and async/await are not magic in the same way some of Rails is. Lots of gotchas and unintuitive behavior, let alone cryptic error messages and stack traces. At least Ruby generally gives pretty useful stack traces. When something breaks, it gives you a pretty clear indication of exactly what line it happened on and what the problem is.
Re:From Node to Ruby on Rails by gkop on Thursday December 16, 2021 @04:22PM (#29584086)
I love Rails (though criticism of its magic is fair), but this isn’t a good analogy. Async/await is literally syntactic sugar over the Promises abstraction. There’s nothing magic about Promises, and certainly nothing magic about async/await. In fact, I’d argue you’re in for a slower learning curve if you believe there to be magic in these areas.
Re:From Node to Ruby on Rails by horsawlarway on Thursday December 16, 2021 @07:20PM (#29585966)
> In fact, I’d argue you’re in for a slower learning curve if you believe there to be magic in these areas.

I 110% agree with you.

This is Rails striking again!

"Don't look at the magic, just memorize it." might as well be Rails' slogan.

Convention over configuration really just means "Memorize all my conventions, and don't ask why I picked them".

Great for the case where your use-case is in line with the chosen conventions and you don't want to think all that hard (or you just need to pump out content - like a contract agency). Pretty terrible for just about everything else.

Re:From Node to Ruby on Rails by tcoff91 on Thursday December 16, 2021 @10:28PM (#29587339)
Promises and async/await are absolutely not magic. Every JS engineer who is competent quickly learns how the event loop works and how promises work.
Re:From Node to Ruby on Rails by davelnewton on Thursday December 16, 2021 @04:44PM (#29584376)
Promises/async/await seem very different than Ruby's (and Rails') metaprogramming to me. I'd need an example of a cryptic stack trace to know exactly what you're referring to--half the problem is because of the overuse of anonymous functions that bork the trace. There's an easy solution to that (and it makes the resulting code easier to test as well).
Re:From Node to Ruby on Rails by weaksauce on Thursday December 16, 2021 @05:12PM (#29584708)
the fact that there is a long chapter in a book series written on the edge cases of javascript[0] leads me to believe that it's not generally well understood either.

0. https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/async...

Re:From Node to Ruby on Rails by horsawlarway on Thursday December 16, 2021 @07:34PM (#29586085)
JS uses an event-loop (which is really just a variation of a message/event queue that we've been using for GUI based applications for decades now). If you understand this, asynchronous code in JS is pretty easy to understand.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Even...

You can go from nothing to mostly full-fledged promises in about 200 lines of code: ex - https://www.promisejs.org/implementing/

async/await is pure sugar on top of promises (it's literally just wrapping the rest of the function in a .then() for you, and coercing the return value of your function to always be a promise)

Re:From Node to Ruby on Rails by davelnewton on Thursday December 16, 2021 @11:59PM (#29587975)
IMO that's an explicitly different issue than a comparison between Promises/async/await and Ruby's metaprogramming, though.

Not to mention that part of the issue with Promises is the various polyfills invented before broad acceptance, which is a separate can of worms, and a different type of complexity than the (relatively) heavy use of metaprogramming in Ruby (relative to JS).

Re:From Node to Ruby on Rails by tcoff91 on Thursday December 16, 2021 @10:24PM (#29587305)
Large Rails projects are the worst I’ve ever encountered as far as being able to find the code that’s actually going to run when I’m looking at a function call in some code. Even with Rubymine, the jump to definition support is a joke compared to typescript, Java, etc…

You just see these functions and there is no require in the file to tell you where they come from. Rails just loads that shit from somewhere. It could be from a mixin, it could be from one of the 50 classes in your hierarchy, who the hell knows. You press jump to definition and rubymine just fucking chokes and gives you like 30 different method definitions with the same name in different places.

Re:From Node to Ruby on Rails by imhilla on Saturday December 18, 2021 @06:19AM (#29603650)
Hey @here i have had the same issue with tracking what is executed when jumping into a new code base, sometimes the code base is so large that instead of contributing you start learning what exists. There is AppMap, google maps for codes, used it quite a few times and unlike rubymine, you can track functions, methods easily by tracing views with just instant clicks. Here is the site https://appland.org/ and they have a vscode extension to ease the process of recording maps
Re:From Node to Ruby on Rails by BurningFrog on Friday December 17, 2021 @12:17PM (#29595132)
Yeah, that's a good summary of my frustrations.

I don't know how much blame to put on Rails, Ruby, or the teams I worked on, but in the end it was very frustrating.

Aside from that I like Ruby a lot, and Rails only a bit less. But it's a big aside :)

Re:From Node to Ruby on Rails by cmelbye on Thursday December 16, 2021 @04:24PM (#29584110)
It might come from the pervasive use of metaprogramming / DSLs in Rails and many other Ruby libraries.
Re:From Node to Ruby on Rails by weaksauce on Thursday December 16, 2021 @05:15PM (#29584752)
I think rails should have explained a bit more about what rails does... every single rails method call like has_one or belongs_to inside a controller is just a method call that sets up a few methods based on the name of the thing you pass into it. not that much magic there. it's just ruby. in fact the single best thing to know that they are not some spooky things to be feared but they are just simple method calls outside the scope of a method.

class Foo; puts "foo.rb was parsed"; end

is a simple example of nothing is really special.