Live data from Hacker News

Ruby 3.2.0 is from another dimension

tomaszs2.medium.com

321–330 of 341 posts

Re: Ruby 3.2.0 is from another dimension

#321
post #277

Earlier quoted context omitted.

I have no idea what they mean by Ruby not having first-class functions. Of course it does. It's a fundamental feature of the language.

No it does not. Ruby has first-class procs. They are not the same thing. It's a fundamental flaw of the language. It's in the Wikipedia page. https://en.wikipedia.org/wiki/First-class_function "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…

> Ruby has first-class procs.

Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.)

> It's in the Wikipedia page.

The Wikipedia page is wrong in that conclusion.

> The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed

A method is a very different thing than a function. But, on a deeper level, I think it is also a mistake to call the thing it is referring the identifier for the method, its just syntax sugar for a symbol passed to a #send call, which, if send isn't overwritten on the sender (which it probably shouldn’t be, overriding send is a good way to cause chaos) will result in the method being called, unless some other method has priority.

> The syntax for calling such a function object differs from calling regular methods

The syntax is different only inna waybthat reflects thebdifferent behavior. Calling #call on a Proc or Method object (again, assuming a sane world where the object’s send method isn’t overidden) does dynamic method lookup on the :call name in the Method or Proc, and its syntax is exactly normal method-call syntax for that behavior (unless you use the shortcut syntax of “.()” for “.call()”, but that's just syntax sugar).

Using normal method call syntax does dynamic lookup on the method name provided in the call on the receiver object identified in the call.

That is, Ruby methods are first class, but what it is a convenient shortcut to think of as “method call syntax” in Ruby is not really method call syntax, it is syntax for a message send that will (by overridable default) result in calling a method with that name if it exists in the ancestor chain of classes for the object, so it is inaccurate to view the “method call” syntax excluding any parameters as “the identifier for the method”.

Re: Ruby 3.2.0 is from another dimension

#322

Earlier quoted context omitted.

While the original Wasm PR description is a useful historical snapshot of the cross-build instructions, the copy in the official documentation is being updated over time: https://github.com/ruby/ruby/blob/master/wasm/README.md

https://www.youtube.com/@tom.stuart/streams this is so fun to watch you! you deserve more publicity, really lovely :)

Thank you, that’s very kind!

Re: Ruby 3.2.0 is from another dimension

#323

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…

Does Ruby still not allow type annotations in the same file as your code? Last time I checked, you had to put them in separate .rbs files. That’s a dealbreaker for me

You can with a third party library, Sorbet. It's not the nicest experience due to not being native but it works much better than you'd expect without being native.

Re: Ruby 3.2.0 is from another dimension

#324
post #320

Earlier quoted context omitted.

Ruby doesn't have first-class methods, either. Python has both first-class methods and first-class functions. > In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing…

Everything is an object in Ruby. Proc objects and Method objects _are_ functions. The same is true in Python -- functions are instances of the 'function' class. What's the difference between a proc and a function? Nothing. "[P]eople like you insist on talking about things you don't actually know about" is insulting language. Consider discussing this with some people you know in real life to see what they think.

You can’t use a Proc or Method value directly to call a method with the Ruby method invocation syntax! In Python and JavaScript and Scheme and OCaml you can! This is the whole idea behind “first-class.” Whether “everything is an object” or not is irrelevant.

Re: Ruby 3.2.0 is from another dimension

#325
post #320

Earlier quoted context omitted.

Everything is an object in Ruby. Proc objects and Method objects _are_ functions. The same is true in Python -- functions are instances of the 'function' class. What's the difference between a proc and a function? Nothing. "[P]eople like you insist on talking about things you don't actually know about" is insulting language. Consider discussing this with some people you know in real life to see what they think.

You can’t use a Proc or Method value directly to call a method with the Ruby method invocation syntax! In Python and JavaScript and Scheme and OCaml you can! This is the whole idea behind “first-class.” Whether “everything is an object” or not is irrelevant.

There is nothing about first-class functions that requires function call syntax to be the same as method invocation syntax. OCaml, Objective-C, and Smalltalk all have different syntax for method invocation and function calls.

To make it concrete: what are you unable to do in Ruby that you're able to do in the languages that you claim do have first-class functions?

Re: Ruby 3.2.0 is from another dimension

#326

Earlier quoted context omitted.

No it does not. Ruby has first-class procs. They are not the same thing. It's a fundamental flaw of the language. It's in the Wikipedia page. https://en.wikipedia.org/wiki/First-class_function "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…

> Ruby has first-class procs. Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.) > It's in the Wikipedia p…

> its just syntax sugar for a symbol passed to a #send call

This isn't the case. If you override `send` it only affects direct usage of `send`. You can't override method dispatch. You can in some other OO languages but not Ruby.

Agreed otherwise. `x.foo` in Python and `x.method(:foo)` in Ruby do the exact same thing -- return a bound method object that can be called. These are both "proxies" in a sense but they're also first-class functions in all meaningful senses.

Re: Ruby 3.2.0 is from another dimension

#327
post #277

Earlier quoted context omitted.

I didn't know Ruby didn't have first-class functions but that's already a massive no for me. You don't need to convince me regarding Python though - it's too convenient to pass up. And despite its shortcomings it's certainly not a language devoid of elegance like some in this thread are painting... Like the old adage goes, there's the languages nobody uses, and there's the languages people talk shit about. Or in simp…

I have no idea what they mean by Ruby not having first-class functions. Of course it does. It's a fundamental feature of the language.

Noted. I've read the rest of the conversation and it's very interesting.

Re: Ruby 3.2.0 is from another dimension

#328
post #326

Earlier quoted context omitted.

> Ruby has first-class procs. Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.) > It's in the Wikipedia p…

> its just syntax sugar for a symbol passed to a #send call This isn't the case. If you override `send` it only affects direct usage of `send`. You can't override method dispatch. You can in some other OO languages but not Ruby. Agreed otherwise. `x.foo` in Python and `x.method(:foo)` in Ruby do the exact same thing -- return a bound method object that can be called. These are both "proxies" in a sense but they're al…

> This isn't the case. If you override `send` it only affects direct usage of `send`.

Correct, I both (minor) confused #send with #__send__ and (more signifcant) misremembered the mechanism of some deep metaprogramming hacks involving a a mostly blank proxy object and #method_missing as using metaclasses and #send/#__send__ hacking; where that came from I don’t know. Should have not mentioned overriding (as its a tangent, in any case, as well as vmbeung wrong) or the #send method and referred to the fundamental underlying message send operation.

Re: Ruby 3.2.0 is from another dimension

#329
post #325

Earlier quoted context omitted.

You can’t use a Proc or Method value directly to call a method with the Ruby method invocation syntax! In Python and JavaScript and Scheme and OCaml you can! This is the whole idea behind “first-class.” Whether “everything is an object” or not is irrelevant.

There is nothing about first-class functions that requires function call syntax to be the same as method invocation syntax. OCaml, Objective-C, and Smalltalk all have different syntax for method invocation and function calls. To make it concrete: what are you unable to do in Ruby that you're able to do in the languages that you claim do have first-class functions?

This is such an asinine argument. Function pointers and passing an environment struct in C let you do everything an OO language does. What are you unable to do in C that you can do in Ruby?

You can implement a type system in Scheme if you really want to, what can you do in Haskell that you can’t do in Scheme?

Just admit you are wrong, bud. It’s not as hard as you’re making it out to be. Strachey’s definition is quite clear and Ruby doesn’t have first-class functions nor first-class methods. It’s a language flaw just like Python’s lambda is a language flaw.

Re: Ruby 3.2.0 is from another dimension

#330
post #326

Earlier quoted context omitted.

> Ruby has first-class procs. Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.) > It's in the Wikipedia p…

> its just syntax sugar for a symbol passed to a #send call This isn't the case. If you override `send` it only affects direct usage of `send`. You can't override method dispatch. You can in some other OO languages but not Ruby. Agreed otherwise. `x.foo` in Python and `x.method(:foo)` in Ruby do the exact same thing -- return a bound method object that can be called. These are both "proxies" in a sense but they're al…

You just gave away the difference right there. x.foo doesn’t “return a bound method object.” It just accesses an attribute and returns the value of that attribute. The attribute can be any Python value. If it’s a callable then it can be called with parens. There is no proxying whatsoever.

In contrast x.method(:foo) does do that proxy construction that you describe… because Ruby does not have first-class functions.

Post reply on HN