Live data from Hacker News

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

groups.google.com

61–70 of 129 posts

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

#61
post #31

"Other syntax differences such as '@foo' versus 'self.foo', or the higher significance of case in Ruby vs Python" ...suddenly wonders if there's a language where both case and indentation are significant.

I think he was talking about the "case" control structure. Or maybe I should just go to sleep... In any case, "case" returns a value, doesn't need breaks and doesn't need to be the same type. That's awesome.

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

#63

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…

If only there was a tool to fix core objects that were tinkered with. Something like... wait. Monkey patching!

But seriously, at his Q&A session on EuRuKo 2010 Matz mentioned that monkey patching issues are going to be addressed in Ruby 2.0. http://nuclearsquid.com/writings/euruko-day2.html

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

#64
post #40

Earlier quoted context omitted.

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 ;)

...and all it takes is one rogue or bad programmer to mess up the code base.

...in either scenario. During code review, however, I'd expect that the good programmers would reach much more strongly to the rogue commits than the mediocre programmers would.

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

#65
Ruby and Python are so similar, in fact, that I'm really surprised that there is no ongoing effort to merge them together. They could really use one another's libraries and various VM implementations, for example; even the parsers are almost identical.

The only things that are really "different" between Python and Ruby are topical features of the grammars of each, that mostly disappear once the code has been AST-transformed. These could likely be expressed more succinctly in terms of a simple common base grammar, and two small, modular sets of reader macros.

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

#66
post #36

Earlier quoted context omitted.

Then why bother with OOP to begin with?

Having a global len() function is very, very linked to polymorphism. You can call it on anything that has a __len__() function defined (i.e., any class that implements something like a "HasLength" interface in Java terms).

If you have __len__() implemented on the object, why not call it directly? If you are dealing with object X, that is of classes A,B,C or D (that all implement __len__), I don't see the fundamental difference between len(X) and X.__len__().

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

#67
I just get a login screen.

+ Newspapers require me to register and login - I go somewhere else.

+ Commercial sites require me to register and login - I go somewhere else.

+ Google requires me to register and login, guess what happens.

I can't be bothered. I've got stuff to write, products to ship, and a life to live. It's just another article. I've saved time by not reading it, and the chances it was useful are small. Besides, skimming the comments has given me enough of the flavor that I don't really think I'm missing much that I didn't get from the comments themselves.

Score another one for the HN community. Thank you.

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

#68
post #7

My biggest beef when I've done a little Python has been inconsistency, such as that over functions versus methods. Ruby has a simpler mental model to me. I hear this has improved in Python 3.0, but it felt bleurgh to use functions like len(str) some of the time and methods at other times (though str.__len__() is a poor workaround here). That said, the reasons have been discussed and defended numerous times, so it's d…

The main reason why I like having functions instead of methods is that it removes the possibility for inconsistency. In some languages, you have some objects with methods named size, some with length, etc. With python, you just have one global len method to remember.

"In some languages, you have some objects with methods named size, some with length, etc."

In ruby you dont. It's #size and ruby is quite consistent in this respect. So it's remembering a method name vs remembering a function name (in a supposedly OO language).

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

#69
post #21

Earlier quoted context omitted.

I am often frustrated by this as well, but I'm not sure it's specific to Python or Ruby. Why is it Math.log(1) rather than 1.log()? And given whatever reason it's Math.log, why is it a.inverse() when a is a Matrix not MatrixMath.inverse(a)? Is there a good guideline for static method vs. instance method distinction?

In python the convention tends to be: a.inverse() -> mutates 'a' to its inverse MatrixMath.inverse(a) -> returns the inverse of 'a', leaving 'a' unchanged

1 isn't a matrix. Integers/floating point numbers are in many languages treated differently than other types for reasons of performance and memory management etc. Ruby isn't different in this respect (IIRC they call it immediate objects). A matrix is a "normal" object in ruby.

BTW the ruby equivalent for the above convention would be (maybe inspired by scheme?)

    a.inverse!() -> mutate a
    a.inverse() -> return the inverse
Which one is more consistent?

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

#70
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)
This syntax difference may seem trivial, but it allows you to do some very interesting things to classes. For instance:

    class Foo
      def self.property(name)
        define_method(name) do
          instance_variable_get(name)
        end
      end
    end

    class Bar 
Now the class Bar has a method called "x", without us needing to explicitly define it.

Ruby's instance_eval method extends this further, allowing you to execute a block of code in the context of any object you wish.

Post reply on HN