News for hackers. Stuff that matters.
Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by stevebmark on Friday October 20, 2023 @04:08PM (#37960920)
I guess you haven't read Eloquent Ruby!
Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by throwanem on Friday October 20, 2023 @05:32PM (#37961803)
The book from twelve years ago?

I carry no brief for Ruby, and method_missing (and its extensive abuse in early Rails) is a major reason why. If you can find no more recent advocacy for that pattern than this, maybe it's time I took another look at the language in earnest.

Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by freedomben on Friday October 20, 2023 @06:16PM (#37962106)
I actually love method_missing. I don't think it should be used for the vast majority of use cases, and most ruby devs shouldn't even know it exists, but the power to reach deeply into things and tap sources is one of the things that makes Ruby amazing IMHO.
Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by throwanem on Friday October 20, 2023 @06:57PM (#37962408)
Oh, I'm not averse to reflection in general! It can be very elegant and still easily understandable when well used, ideally at compile time. No, it's just that this particular example was once egregiously overused, with an excess of cleverness aforethought that made debugging anything far more difficult than it really had any need to be.

It's not even that I can't see how the Rails implementors got there; on the one hand it was very early in the development of the modern web concept and nobody really knew what worked and what didn't yet, and on the other, a more modern pattern would have probably been very slow anyway in those days. Still, the experience left a bad taste that I've found hard to shake.

Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by stevebmark on Friday October 20, 2023 @07:09PM (#37962502)
Now you have your recent advocacy, which is common in the Ruby community. Embrace magic, embrace indirection.
Re:"Useless Ruby sugar": Pattern matching (Pt. 1) by JohnBooty on Saturday October 21, 2023 @09:40AM (#37966714)
Ruby is really good as a language these days, and has only gotten more performant.

Rubocop has gotten wide adoption and has standardized a lot of good practices. By default it's awfully strict.

I worked full-time with Ruby for 9 years across several companies and I solemnly swear that I never saw a single person use method_missing or consider it as anything other than a mostly terrible idea.

Never saw it used once, or even considered once, in actual application code.

Generally that was the case with any of those "sharp knives" or "potential footgun" language features. Monkey patching is another good example. Used to be extremely common and even recommended, but now it is extremely frowned-upon and used only with extreme care/desperation in application code.

The "problem" with Ruby is that it has become kind of a monoculture around Rails. Rare to see it used for anything but Rails these days. People who want a fun casual language are using Python because Python has that booming ML-adjacent ecosystem and a strong foothold in academia/science.