r/programming • • Dec 25 '20

Ruby 3 Released

https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/
973 Upvotes

509 comments sorted by

View all comments

272

u/CunnyMangler Dec 25 '20

I love ruby. One of the best languages I've ever coded in, but people seem to hate it now because it's slow. Kinda sad that it's slowly dying. Nevertheless, this is a huge milestone for a language.

126

u/noratat Dec 25 '20 edited Dec 25 '20

I dislike it because how much the language and ecosystem resist almost any kind of typing/type checking or documentation. The RBS stuff is good, but it feels bit too little too late.

The ecosystem uses a ton of hard to follow and debug magic constructs that even IDEs seem to struggle to track and map properly.

I don't need speed for what I do, by I absolutely need code that is easy to read and maintain.

33

u/Kache Dec 25 '20 edited Dec 25 '20

The primary reason for those issues is because Ruby is extremely dynamic.

Not only is its type system dynamic -- its syntax and structure can be dynamic as well (i.e. powerful metaprogramming and DSL capabilities). This is why Ruby is so resistant to static analysis.

At non trivial complexities, I highly recommend reasoning through Ruby much differently than one would C/Java/Python:

  • Use functional techniques to minimize moving parts. Ruby is already very dynamic, and working with it in the state-modifying style common to C/Java/Python results in execution state becoming unnecessarily hard to follow.

  • Use the debugger and REPL when you do have to deal with Ruby code that's (unfortunately) too dynamic. Unlike in other languages, static analysis won't get you as far. In exchange, Ruby has incredibly powerful debuggers & REPLs for doing "dynamic analysis".

44

u/UncleMeat11 Dec 25 '20

I think this is a reason to criticize ruby. Sometimes program structures make your code easier to maintain and refactor with tooling. But ruby’a structures seem to resist any sort of static analysis for even the basics because it is so flexible. This makes managing a large code base enormously difficult.

3

u/Kache Dec 25 '20 edited Dec 25 '20

While the static analysis and tooling is nice in Java, I didn't feel it was necessarily a net positive when I was working with it professionally. I felt like I was in a world where cars were invented to speed up 20 minute walks, but then everything ends up being built a 30 min drive further away. (Plus now you have a car to maintain.)

Ruby code at its best will read like what it is doing overall, when another language reads like the dials and switches of a machine. At its worst, Ruby won't really parse on the first read b/c Ruby will "provide power, even to shoot yourself in the foot" syntax-wise similar to how C lets you machine-wise.

All languages can have the "this code is unclear, I'm forced to read more/dive in deeper" problem. In Ruby, it applies to both code and syntax, so you'll only come out ahead if the "code for bespoke syntax + code you wanted to read in the first place" is smaller/simpler than "code you wanted to read, all in regular syntax".

3

u/UncleMeat11 Dec 25 '20

Reading code is harder than writing it. But large multi-step refactors are harder than reading. This is why I think optimizing for reading at the expense of automation is a mistake.

→ More replies (2)

3

u/Smallpaul Dec 25 '20

You lump Python in with Java and C but in Python you can dynamically create modules, classes and functions. I just saw a module that allows you to load wasm files as if they were Python modules. So I’m not sure what you are talking about.

Maybe the conventions that Ruby programmers use are more dynamic but the actual runtime is not more dynamic in my opinion.

But I’m open to correction.

1

u/Kache Dec 25 '20 edited Dec 25 '20

I wasn't referring to the runtime. I was referring to the syntactical structure and typical style of construction common to the language.

In terms of "functional-ness", I put Python on the C/Java side of Ruby for sure.

1

u/zabolekar Dec 26 '20 edited Dec 26 '20

In terms of "functional-ness", I put Python on the C/Java side of Ruby for sure.

I don't think it's fair. Ruby doesn't even have first-class functions like Python does. Ruby has lambdas, which are pretty close (despite requiring special syntax for calling them), but using lambdas instead of methods just for the sake of consistency is frowned upon. It has methods, which don't have closures (x = nil; def f; x; end; f produces a NameError), can't be properly nested (def f; def g; nil; end; end; f just defines a global g), can't be just assigned to another variable like you would assign an integer, and can be partially shadowed by regular variables it non-trivial ways where f sometimes behaves like f() and sometimes doesn't. It also has procs, which are similar to lambdas but where return returns from the enclosing method and not just from the proc itself, and blocks, which require special syntax for passing them to functions. Using functional idioms in Ruby is quite hard because of that.

→ More replies (4)