Live data from Hacker News

Ruby 3.2.0 is from another dimension

tomaszs2.medium.com

91–100 of 341 posts

Re: Ruby 3.2.0 is from another dimension

#91

Earlier quoted context omitted.

When I looked at Python vs Ruby many years ago, I found the opposite: Why does Python have (special) functions like len() and map(), instead of 'properly' supporting both OOP (len should just be a method on objects) and/or FP (support multi-line lambdas so I can actually use map/filter etc). I never understood how this can be considered consistent at all, and those IMHO language design warts made me look into Ruby at…

Map/filter are considered inferior in Python to list comprehensions. res = [x**2 for x in range(10) if x != 5]

Before Ruby introduced filter_map:

res = (1..10).select { |x| x != 5 }.map { |x| x ** 2 }

With filter_map:

res = (1..10).filter_map { |x| x ** 2 if x != 5 }

In both cases, I think the Ruby solution is more readable.

Python list comprehensions invert the subject (data) and the verb (action). You see what will be done before you see what the subject is. I would argue that showing the subject first allows easier code review as you know immediately what you are working with.

But beyond that, the first Ruby example tells you in English what is happening. "take this range", "select a subset", then "map some actions to the elements".

And the filter_map abbreviation does the same, telling you "take this range, filter it and perform an operation on the remaining elements".

Python tells you nothing... and what it does say is in awkward order.

As functional and data-oriented programming is gaining in popularity (for good reason), adopting some functional practices in Ruby is a pleasant experience. Doing the same in Python exposes more of these... irregularities.

Edit - I always forget how to format symbols in these comments!

Re: Ruby 3.2.0 is from another dimension

#92
post #62

Earlier quoted context omitted.

Those functions take any object that supports the iteration protocol. There’s no need for adding say, len, to every object that needs a len function. I’d argue that is consistent. Sure, multi line lambdas might be nice, but equally you can define functions wherever you need them so it’s not really all that different.

> There’s no need for adding say, len, to every object that needs a len function. fwiw, Ruby does the same thing, but using the Enumerable mixin rather than a free floating function. > I’d argue that is consistent. I don’t understand this argument. It’s convenient and more efficient to write, yes. But how is it more consistent to have two different calling conventions? The claim that there’s one way to do something i…

By which I mean that you can consistently use `len` etc on any iterable and they will always behave in the same way. You learn them on day one and they work consistently in every place you see them forever.

Re: Ruby 3.2.0 is from another dimension

#93
post #56
post #29

Earlier quoted context omitted.

Python gained traction because of Google (Google used it initially then Guido worked for them for a decade+, vs. Matz at Heroku/salesforce) and then because it's the easiest way to use ML libs. That's it. It's slower than Ruby, has worse package management and less consistent syntax but if you want to use Tensorflow, PyTorch, etc..., it's the default.

> It's slower than Ruby. Any reference/numbers to back this up ? Just genuinely curious about this.

[deleted]

Re: Ruby 3.2.0 is from another dimension

#94
post #29

Earlier quoted context omitted.

Python gained traction because of Google (Google used it initially then Guido worked for them for a decade+, vs. Matz at Heroku/salesforce) and then because it's the easiest way to use ML libs. That's it. It's slower than Ruby, has worse package management and less consistent syntax but if you want to use Tensorflow, PyTorch, etc..., it's the default.

That's a fairly Silicone Valley focused argument. I don't subscribe to the theory at all that Google closed internal use of Python was instrumental in its adoption. Django was released in 2005 and RoR in 2004. I suspect my journey was similar around then (late 2005), I had used PHP, classic ASP and a little Perl. I was looking for something better, read the tutorials for both Django and RoR. Had a look at what deskto…

Had a similar journey, started with ASP in the 2000s, then PHP around 2003, then worked with both RoR and Django professionally for a few years.

As much as I liked RoR for its scaffolding and easiness of bootstrapping new CRUD projects, over time with larger codebases and teams it just starts to be a mess. Ruby programmers love the terseness of the language and write some of the most ungrokable code I've encountered (second only to some Scala codebases I worked with). That and the magic of autoloading modules which then could introduce a DSL, the usage of mixins that are hard to trace where they are loaded from, and a lot of other magic features that are extremely opaque to parse through and debug is, ultimately, what made me abandon Ruby and RoR.

It has its uses but I've yet to see a decent legacy RoR codebase without these pitfalls of magic, after so many years professionally working with code I prefer any language environment that is explicit, Ruby is not explicit.

Re: Ruby 3.2.0 is from another dimension

#97

Ruby is my favorite language, and often it is a joy to use because of its combined attributes of brevity, expressive power, and feature consistency. It's disappointing that there are so many more jobs for another popular language - one that lacks the elegance and consistency but which has a larger ecosystem. As far as I know, the only well known reason for a company to choose Ruby is if they want Rails (and obviously…

I disagree. Ruby has no more elegance or consistency than the other popular language, and it objectively has a much poorer selection of libraries.

Re: Ruby 3.2.0 is from another dimension

#98
post #85
post #65

Earlier quoted context omitted.

How does having a function instead of a method indicate that it's out-of-place? Every Ruby tutorial explains that an exclamation mark means in-place, and this convention is consistent across Ruby libraries, unlike Python.

It's a convention, quite a nice one, but not all libraries are consistent and it does have different meanings too (! is sometimes used for "raise an error instead of returning a boolean"). In the Python case, `list.sort()` operates on the object, so you can kind of expect it to do mutation (but there's no convention / guarantee). Though it only makes sense as a function that the list object itself implements. `sorted…

> it does have different meanings too

the meaning is the same high level: it has side effects, being it a destructive update, an in place operation or throwing an exception.

> `sorted` is a general function that gives you a sorted list from any iterable

iterable in Python is a very loose concept though.

And it's not very consistent too

    sorted("gheliabciou")
    ['a', 'b', 'c', 'e', 'g', 'h', 'i', 'i', 'l', 'o', 'u']
you give it a str it returns a list of char

in Ruby it makes much more sense

   "gheliabciou".chars.sort.join
   "abceghiilou"
You take out the chars from the string, sort them and then join them together again

because a string cannot be sorted, sorting a string makes no sense, you sort the chars composing it.

Also, Python could not do this for many years, while Ruby could no prob

  sorted("gheliabciouß⌚⌨⌛🆔🉑🈶🈚🈸🈺🈷🆚🉐㊙㊗🈴")

edit: Python also shows some very counterintuitive semantic

take the example above, to return a string you use

  ''.join(sorted("gheliabciou"))
  'abceghiilouß'
which is probably the last thing someone would think of.

sorting a list does not produce any output, because sort is _always_ in place, so you have to waste a variable to sort a list because you can't sort it inline

   list("fedcba")
   ['f', 'e', 'd', 'c', 'b', 'a']

   print(list("fedcba").sort())
   None # 
again, highly unexpected

my favourite

  print([c for c in "bca"].sort())
  None # 

Re: Ruby 3.2.0 is from another dimension

#99

Ruby is my favorite language, and often it is a joy to use because of its combined attributes of brevity, expressive power, and feature consistency. It's disappointing that there are so many more jobs for another popular language - one that lacks the elegance and consistency but which has a larger ecosystem. As far as I know, the only well known reason for a company to choose Ruby is if they want Rails (and obviously…

I disagree. Ruby has no more elegance or consistency than the other popular language, and it objectively has a much poorer selection of libraries.

Lack of libraries is noticeable - especially since I've worked with python for past years.

However Ruby's syntax is way nicer. I can actually write what I think instead of having to translate my thoughts into python. Of course over time working with python has made my thoughts to conform into more pythonic way, but I still occasionally find myself thinking how something would have been way nicer to write in ruby instead.

Re: Ruby 3.2.0 is from another dimension

#100
post #55

>The new JIT compiler based on ground breaking Basic Block Versioning already gives some exciting results >This novel approach lazily generates type-specialized versions of basic blocks on-the-fly while propagating context-dependent type information. Does anyone know how it is different from tracing JIT compilers?

JIT compilation is done lazily on a per basic block level (so you only JIT blocks you're about to run). It keeps track of statically known information for specific basic-blocks and specializes different versions of basic blocks based on this. So if you're coming from an if-statement checking the type of X, into a new basic block, then the JIT specializes the block based on the knowledge that X indeed has said type (so it can specialize operations or skip future checks).

I can highly recommend watching their presentation on it: https://www.youtube.com/watch?v=PFb5wNj2ztM

Post reply on HN