other-languages

mauricio.szabo 2024-06-06T15:54:13.346129Z

I just found out that if I use Ruby' "destructuring" in a method's parameter, it basically becomes "magical". For example, if I define def some_method(arg1: 10), this some_method now somehow accepts zero parameters, but if you call it with a map-like thing, it will be accepted... but not if you call with an actual map. Like, I can do some_method(arg1: 200), and it works, but it won't work if I do some_method(parameter), even if parameter is a map. In fact... I need a special syntax (they call it "double splat") to call with an arbitrary variable. The method itself registers as accepting zero arguments. Ruby is... very weird... and it's becoming weirder and weirder...

2024-06-08T07:38:40.888099Z

Languages in general is optimized for specific objectives. It is always easy to point to the unoptimized parts for criticism. Based you your experience what does ruby optimize for?

Cora (she/her) 2024-06-08T08:00:38.544949Z

the creator of ruby claims that it's "optimized for programmer happiness", but having worked on it professionally for over a decade before bailing on the language it seems like it's optimized for superficial delight

Cora (she/her) 2024-06-08T08:01:36.650489Z

I still use ruby, but I use it for text processing and for when I need something just a little more powerful than shell scripts, it's a perl replacement

Cora (she/her) 2024-06-08T08:04:18.324439Z

superficial delight meaning "not typing pesky delimiters" and "not being restricted in what you can customize and extend at runtime", but long-term it leads to syntax warts like this and unpredictable systems that need a mountain of (always slow) tests just to have any confidence in a large application

mauricio.szabo 2024-06-09T03:24:50.293799Z

I think Ruby optimises for "reading like natural language". The problem is, when you optimize for that, you unoptimize for everything else.

mauricio.szabo 2024-06-09T03:26:37.228219Z

A good example is how the community decided to use DSLs for basically everything. This week I had to literally write almost the same 30 lines in five different files because they are all DSLs so I can't just re-use code - because there's no "data" or even "API" in use, it's all custom syntax

mauricio.szabo 2024-06-09T03:28:21.941679Z

@corasaurus-hex Ruby became more tolerable for me because I ported my Clojure plug-in for Ruby. Amazingly, I have a nREPL for Ruby, and I connect to it, can evaluate code, load file, and check results. Otherwise, I would probably be screaming right now (or, at least, screaming more than what I am hahahahaa)

😂 1
😭 1
Cora (she/her) 2024-06-09T04:24:17.195749Z

instead you could just include a module in each of those classes and use the included hook to metaprogram those DSL calls!!

😅 1
2024-06-09T05:17:13.104189Z

@mauricio.szabo Maybe that's why majority of Ruby is used with a dsl (I.e. Rails). That make sense

2024-06-06T17:08:05.172639Z

yeah, it's not destructuring, it's a named parameter

2024-06-06T17:08:27.303299Z

it's an annoying difference

seancorfield 2024-06-06T17:22:52.777579Z

When I did the Washington University "Programming Languages" course (CSE341), they taught Racket (dynamically typed FP), Standard ML (statically typed FP), and Ruby (dynamically typed OOP) -- my first real exposure to Ruby -- and it is a weird language in so many ways. I didn't care for the syntax in the first place, but the metaprogramming and every class being open for extension -- even the built-in classes like numbers -- seemed to make it nearly impossible to tell what any given piece of code would do purely by inspection, since any behavior can be modified anywhere else in the code. 🤯

mauricio.szabo 2024-06-06T17:29:43.016669Z

@nbtheduke yes, it's a named parameter... except that it doesn't behave as a parameter. If I try to do some_method(parameter) in my example, it would crash with Wrong number of arguments (expected 0, got 1)

2024-06-06T17:30:20.615349Z

huhhh

2
mauricio.szabo 2024-06-06T17:38:53.153809Z

Yep, that was the behavior starting at Ruby 3.0

mauricio.szabo 2024-06-06T21:50:29.329469Z

I think what bothers me on this is this whole weird thing that Ruby have, that are "special parameters" to methods. There are "regular" parameters, like def a_method(a, b), there are "blocks" like def other_method(&a_block), and now "named parameters" is a special thing too, with this syntax def named_method(a:, b:) Like, I can't call other_method(something) because something will be interpreted as a "regular parameter", nor I can call named_method(something).

Cora (she/her) 2024-06-07T03:41:00.872699Z

I feel like this is due to the ruby allergy to typing delimiters like parens and curly braces, creating a syntax that thrives on ambiguity and special cases

âž• 1
Cora (she/her) 2024-06-07T03:42:21.515769Z

and then if you take that and accrete new features on top of it, constantly compromising with new ambiguous syntaxes, you end up with this mess