Live data from Hacker News

What's better about Ruby than Python? - comp.lang.python

groups.google.com

81–90 of 129 posts

Re: What's better about Ruby than Python? - comp.lang.python

#81
post #37

Earlier quoted context omitted.

I HATE dealing with first class functions in Ruby. I understand that it was a design choice, but man, in Python you can pass a function or a lambda and you just don't have to worry about which one you're calling. In Ruby, () will explode on a Proc object. What is with that?!!?

You can call a proc with [] p = Proc.new {|str| puts "Hello #{str}" } p["World"] # prints "Hello World" :)

I'm aware of this, but it's still not (). You still must be aware that you are dealing with an unbound proc object, and it must be handled differently than usual!

Re: What's better about Ruby than Python? - comp.lang.python

#82
post #37
post #19

Earlier quoted context omitted.

That may accomplish the same thing, but the direct translation would be: if baz > 10 func = method(:foo) else func = method(:bar) end result = func.call Here, we actually deal with the Method objects, rather than just sending a dynamic message. Although the send() approach would be closer to idiomatic Ruby, I wanted to emphasize that dealing with methods as first class objects in Ruby is indeed possible.

I HATE dealing with first class functions in Ruby. I understand that it was a design choice, but man, in Python you can pass a function or a lambda and you just don't have to worry about which one you're calling. In Ruby, () will explode on a Proc object. What is with that?!!?

Well, a Method object and a Proc are two different things, but somewhat similar, so it still makes sense to discuss Proc behavior here. I would like it if this worked:

    a = lambda { |x| x + 1 }
    a(3) #=> 4
But since it doesn't, the alternatives are not too bad (though likely far too numerous for Python tastes)

    a[3] #=> 4
    a.(3) #=> 4 (on Ruby 1.9)
I think that Ruby's ability to call methods without () make for better readability in the case of writing domain specific interfaces, but come at a cost in other places. Personally I think it's a worthwhile tradeoff but I can see the other side of the argument.

Re: What's better about Ruby than Python? - comp.lang.python

#83

There are two things that Ruby has that Python doesn't have a good syntax for. One is blocks; in Ruby, I can write: foo { |x| puts x } Whilst in Python, I need to write: def tmp(x): print x foo(tmp) It's not really very nice. The other thing is that Python has no concept of context. In Ruby, I can type: foo(x) And it will execute foo(x) for the containing object. In Python, the closest equivalent would be: self.foo(x…

> The other thing is that Python has no concept of context Rather, I'd say that part of the zen of python is: implicit is better than explicit , and I prefer python's behavior in this instance.

You've got that backwards for Python: Explicit is better than implicit.

Re: What's better about Ruby than Python? - comp.lang.python

#84
post #42
post #37

Earlier quoted context omitted.

I HATE dealing with first class functions in Ruby. I understand that it was a design choice, but man, in Python you can pass a function or a lambda and you just don't have to worry about which one you're calling. In Ruby, () will explode on a Proc object. What is with that?!!?

Because () doesn't call a method, it's simply used where a method call occurs. To call a callable object, you use #call or (as mentioned by epochwolf) #[], the latter of which I personally detest. It's fun to contrast this with Lua, by the way.

It's the inconsistency that bothers me.

In Python, you can make anything callable by providing a __call__() method, and the parentheses will work as expected. This makes functions fungible with anything, including any object or anonymous function.

In Ruby, only methods are callable, and everything else must be called with the call() method, which means you can't use one in a place where the other might be expected. They're two concepts with the same verb--call--that require different syntax. It's inconsistent.

Re: What's better about Ruby than Python? - comp.lang.python

#85
post #54
post #37

Earlier quoted context omitted.

I HATE dealing with first class functions in Ruby. I understand that it was a design choice, but man, in Python you can pass a function or a lambda and you just don't have to worry about which one you're calling. In Ruby, () will explode on a Proc object. What is with that?!!?

Are you actually passing around methods in Ruby and, if so, why? As I've pointing out in the past ( http://news.ycombinator.com/item?id=1141245 ), passing around methods is very rare in Ruby due to the flexibility of Procs.

Interesting! I am a half-breed; I write Python at my day job and Ruby in my personal projects. You seem to be suggesting that I am sort of making a mountain out of a molehill. Can you perhaps elaborate on this? I have definitely felt this pain before; I'm not just complaining about it because I "like the Python way more." But if I'm not using Ruby "as intended," I would like to know how I should be using it instead! I feel like the "Python way" is powerful because you don't have to think about whether you're dealing with an anonymous function or a function, whereas in Ruby you must know for sure which one you are dealing with, because they are invoked differently. I'm interested to know how it isn't really a problem, if that's how you feel.

Re: What's better about Ruby than Python? - comp.lang.python

#86
post #75
post #25

The biggest difference between Python and Ruby is in the mindset of the developers that choose them. I think of Ruby and Python as two languages standing back-to-back in the same spot, mostly unaware of each other, greeting developers who come from different directions.

I know it's early yet, so take this with all appropriate grains of salt, but that is easily the most insightful comment I've read today, and really drives home a point I've been trying to make for awhile (and probably failed to). I started out with Ruby, because of Rails, and just never seemed to quite make it jive with me mentally. When I found Python (because of Django), everything clicked more. I'm not even sure i…

Possibly, your greater experience was the difference. I don't know what experience you had before, but if you came to Ruby with no experience in a "dynamic" language, everything seemed new and hard-to-understand. Later, coming to Python, you probably understood everything better as you were learning it, having had experience with Ruby.

Just a guess, of course.

Re: What's better about Ruby than Python? - comp.lang.python

#87

Basically Ruby and Python fill the same niche. When two species fill a different niche in nature, they can co-exists. When they fill the same niche, it is a bitter fight for survival.

more evidence: vi vs The Unholy, er, I mean, Emacs

One of those is an editor. The other is a lisp environment with editing functions.

Re: What's better about Ruby than Python? - comp.lang.python

#88
post #40
post #4

Earlier quoted context omitted.

The fact that anyone at any point can monkey patch any built-in is a potential liability for large teams, with average programmers. It must be addressed by culture and code review that you may or may not have. Still worth it though :)

In what situation is it actually a good idea to employ a large number of bad programmers, rather than a small number of good ones? We shouldn't be making trade-offs for the sake of bad ideas ;)

There's a distinction to be made between preventing risky behaviour and relying only on a programmer's good judgement to avoid mistakes. Even if your team is solely good programmers there's a lot to be said for discouraging unsafe behaviour by default since anyone can have a bad day, distraction, etc.

I view this situation as somewhat analogous to having guards on power tools: even a highly skilled operator doesn't want to rely on always doing something perfectly.

Re: What's better about Ruby than Python? - comp.lang.python

#89

The title made me nervous that this would be run-of-the-mill fanboy garbage. But I trust the author (Alex Martelli), so I read it, and I'm glad I did. It's reasonable and sane. My two big take-away points: 1) It's very nearly a wash. Ruby and Python are so close together (beneath any superficial differences) that distinguishing is almost an exercise in futility. 2) The key thing about Ruby he doesn't like is its "TOT…

My impression of the Ruby community, especially the OSS part of it, was that they were explicitly more about tinkering than enterprise. Certainly characters like _why were in that camp. In regards to monkey-patching, while I'm not a Ruby programmer by any means, I sorely feel its absence in other languages. It's in JavaScript (expando objects as well as being able to override and overwrite built-in methods of existin…

My impression of the Ruby community, especially the OSS part of it, was that they were explicitly more about tinkering than enterprise. Certainly characters like _why were in that camp.

I don't entirely disagree with the larger sentiments, but I worry about the tone of the word 'tinker'. That is, the Ruby world is full of playful characters, and often displays a spirit that is far from corporate. However, many Ruby (and RoR) apps are also serious businesses at this point. There are also many libraries that don't charge money, do exhibit that playful or exuberant spirit, but also provide hard-core real-world functionality (e.g., Nokogiri).

tl;dr The word 'tinker' is a bit trivializing (perhaps unintentionally on Martelli's part). The division between 'tinker' and 'enterprise' doesn't fully or properly cut up the problem space. It's a binary view of a multi-faceted world.

(For whatever it's worth, this is my view as someone on the outside of this whole situation. I use Ruby and Perl about equally, primarily for systems administration and personal projects.)

Re: What's better about Ruby than Python? - comp.lang.python

#90
post #86
post #75

Earlier quoted context omitted.

I know it's early yet, so take this with all appropriate grains of salt, but that is easily the most insightful comment I've read today, and really drives home a point I've been trying to make for awhile (and probably failed to). I started out with Ruby, because of Rails, and just never seemed to quite make it jive with me mentally. When I found Python (because of Django), everything clicked more. I'm not even sure i…

Possibly, your greater experience was the difference. I don't know what experience you had before, but if you came to Ruby with no experience in a "dynamic" language, everything seemed new and hard-to-understand. Later, coming to Python, you probably understood everything better as you were learning it, having had experience with Ruby. Just a guess, of course.

I'd had some experience with Perl and quite a bit of experience (had built a couple large-ish apps) in PHP.

The reason I referenced Rails and Django as motivators in finding those languages is because after having built and then forced to maintain an enterprise-class application in PHP, I REALLY liked the notion of an MVC framework, and things like Cake and Symfony weren't out (or at least I didn't know about them) yet.

So, yeah, I wasn't a programming newbie altogether, but I wasn't as comfortable in just picking up new languages either.

Post reply on HN