Hacker News new | ask | show | jobs
by burlesona 902 days ago
Ruby is basically a less popular but more elegant Python. It’s a solid general purpose language, but especially good at shell scripting, data munging, etc.

If you’re fluent in Node and Python it should be quite easy to learn. The downside is it’s not going to do anything fundamentally new for you coming from those languages. The upside is mostly aesthetic, Ruby offers and encourages really beautiful ways of expressing code, and it’s neat to experience that.

2 comments

Having tried to use Ruby for text processing specifically, I'm not sure I agree it beats Python at that particular task. Maybe I'm just used to the Python way of doing things, but I found it difficult to work with the lack of first-class functions and iterators/generators, as well as the general iteration protocol.
> but I found it difficult to work with the lack of first-class functions and iterators/generators, as well as the general iteration protocol.

Ruby has iterators/generators. It doesn't have first-class functions because it doesn't have functions at all, but blocks/procs serve the same purposes.

I don't know Ruby, but it kinda sounds like Ruby just calls first-class functions blocks.
No, blocks are not first class (procs are, and procs are the closest thing Ruby has to functions, and a method definition can bind convert the block passed to the function to a proc if a first-class value is needed.)

Blocks are a syntactically special single argument to a method that can either be yielded to (a Ruby construct similar to a function call but which only applies to the block passed to the current method) or converted to a proc (but the latter only as part of the method definition, since they aren't first class and thus cannot be manipulated or referred to directly.)

No, blocks are lambdas.
No, in Ruby lambdas are lambdas (and are a special type of proc); the longhand way to create a lambda is to call Kernel#lambda and pass it a block (though modern Ruby has a special shorthand syntax for lambdas, as well.)

Blocks are sort of like anonymous function literals that are not first class, one (but no more than one) of which may be attached to a function call.

I think you may just be used to Python still relying on functions for string processing, where Ruby has methods on the String class for manipulating strings.

It seems to me that Python still has these holdovers from when it was not fully object-oriented, where a lot of string and data structure manipulation is done with language-level functions rather than methods on the objects, which can be quite confusing.

I find the opposite. Ruby has a longer list of String, Array and Hash methods/functions and they're also more useable.

Another issue I had was that Python's test frameworks like PyTest were just so weak compared to the likes of MiniTest and RSpec.

> lack of first-class functions and iterators/generators, as well as the general iteration protocol

can you elaborate on what you miss here? ruby has a robust enumerable suite of methods so i'm curious what you found lacking

> ... lack of first-class functions and iterators/generators, as well as the general iteration protocol.

I'd love to hear what makes you say this - none of it is meaningfully true (ruby doesn't have functions, but it has blocks and callables).

It has:

https://docs.ruby-lang.org/en/master/Enumerator.html

What is the distinction between a function and a proc? I would say that a proc is a (first-class) function.
As I said, claiming that ruby doesn't have first-class functions isn't "meaningfully true". Ruby does not have functions, only methods. But that's mostly irrelevant.

https://en.m.wikipedia.org/wiki/First-class_function#Languag...

> The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed. It must first be retrieved into a Method or Proc object to be used as first-class data. The syntax for calling such a function object differs from calling regular methods.

https://blog.appsignal.com/2018/09/04/ruby-magic-closures-in...

> Ruby doesn’t have first-class functions, but it does have closures in the form of blocks, procs and lambdas. Blocks are used for passing blocks of code to methods, and procs and lambda’s allow storing blocks of code in variables.

> but especially good at shell scripting, data munging

Add to this also Shopify, Github, Gitlab, Basecamp and some others and you will see that Ruby can be use for more than shell scripting and data munging. Yes they are Rails but Rails is written in Ruby so they are Ruby.

Stripe is a big "ruby but not rails" shop, iirc.