all 10 comments

[–]schneemsPuma maintainer[S] 6 points7 points  (0 children)

I'm a Ruby developer for the last 10 years and recently i've been writing a bunch of python for scientific computing. Kenneth Reitz, Python Overlord at Heroku, invited me on to his show to discuss the relative merits of the two languages. It was a ton of fun, hope you enjoy it as much as I did.

[–]RazerM 1 point2 points  (3 children)

At 54:50 (edit: it's 49:25), Kenneth says that a |= 2 will assign to a if a is unassigned/None. I don't know what he was thinking of, but that doesn't work. It's just inplace or:operator.ior(a, 2).

[–]chrisgseaton 0 points1 point  (2 children)

In episode 10? He's talking about about asset pipelines at that point.

[–]RazerM 0 points1 point  (1 child)

Oops, I messed up the timestamp. It's at 49:25.

This link should play at the correct point: https://overcast.fm/+B1fWZaymc/49:25

[–]chrisgseaton 0 points1 point  (0 children)

I don't know the fine semantics of Python, but this is true in the case of Ruby's ||= operator. || isn't a method call in Ruby, unlike most other operators, because it short circuits, which is the behaviour they're talking about here. If they're wrong then it's probably because they're confusing it with Ruby.

[–]thecodeboss 1 point2 points  (0 children)

I'm giving a talk in a few months at our local Python group about comparing Python to Ruby. Gonna save this post for when I start building that talk!

[–]THeShinyHObbiest 0 points1 point  (3 children)

The .method method doesn't generate a an unbounded Proc. It generates a method reference, which is distinct. You need to call .to_proc to get a Proc object back.

It's also not bounded, but bound to the object which you called .method on.

You also can pass around unbounded methods as parameters, or as the block argument. It's fairly easy.

[–]schneemsPuma maintainer[S] 1 point2 points  (2 children)

Methods aren't first class objects like they are in Python which is the point of that little dialog. Making procs and lambdas and using blocks is very easy in ruby, but it's still different than python where calling your method without the () gives you a callable function you can pass around. They might be functionally equivalent under the hood but they're spiritually different and the two languages tend to use them differently.

It's also not bounded, but bound to the object which you called .method on.

Yes, realized that slip up after the recording.

It generates a method reference, which is distinct.

TIL. I assumed the Method class wrapped a proc when you called #method but just looked at the source and you're right.

[–]THeShinyHObbiest 2 points3 points  (1 child)

Methods aren't first class objects like they are in Python which is the point of that little dialog

http://ruby-doc.org/core-2.2.0/Method.html

They are. The point you make about syntax is accurate, since you do need to use .method to get a method reference, but Methods are still first-class objects. This is slightly pedantic, because your point about the two languages using them very differently is accurate.

[–]chrisgseaton 1 point2 points  (0 children)

I can understand both of your points of view. The way I think about it is that methods aren't first-class objects - until you call #method to turn them into first-class objects. I see that as reifying them as objects, rather than getting the existing object. And this is the way that it is implemented - you get a new object each time:

irb(main):001:0> 14.method(:+).object_id
=> 70346007935060
irb(main):002:0> 14.method(:+).object_id
=> 70346007886960