Live data from Hacker News

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

groups.google.com

91–100 of 129 posts

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

#91
post #36

Earlier quoted context omitted.

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__().

The "magic methods" wrapped in in double-underscores are special because other parts of the language's syntax rely on them always meaning the same thing. (Some room for programmer misbehavior here.)

Example: If __len__ is defined on an object x, and __nonzero__ (Py2) or __bool__ (Py3) is not defined, then "not x" will test if x.__len__() == 0.

Similarly, __contains__ interacts with "foo in x", and __eq__ and __hash__ are expected to play well together for hashable objects (e.g. unique members of a set).

The double underscores are a useful code smell that indicates you're changing how an object interacts with Python's syntax.

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

#92

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…

Not disagreeing with you. In fact, the first example is one reason why "print" was changed from a keyword to a function in Python 3:

  myfunc 

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

#93
post #36

Earlier quoted context omitted.

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__().

There really is no difference except that len() will raise an error if no __len__ method is found on the object.

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

#94

Earlier quoted context omitted.

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 (…

I agree completely. I tend to dislike the phrase "enterprise development" anyway, because it implies that somehow our programming is suddenly different just because a company uses it. But, I try to write for my audience.

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

#95
post #69

Earlier quoted context omitted.

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 inver…

  1 isn't a matrix
A Fixnum could be interpreted as a 1x1 matrix. For some recursive solutions, it would probably be nice of MatrixMath.inverse accepted it as such, as well as [[1]].

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

#96
post #71
post #43

Earlier quoted context omitted.

if ruby is an extreme to the left, and java an extreme to the right, then python is also extreme to the left. The difference between python and ruby in dynamicity is really small. Python is not in the middle of ruby and java. Python is virtually on top of ruby.

A fair point. Maybe 'optimum' would be a more useful concept here than 'centre'... I see Python's position on the dynamicity (ugh) spectrum is in line with it's philosophy on readability. (On a side note - your definition of 'extreme' rather depends on what outliers you have. I do love it when the US media refers to the Democrats as 'left of center' ;)

yup, republican and java are in the same camp ;)

On a serious note, I've been doing ruby as my job for about 5 years and I work at a giant corporation with a few hundred programmers. In those 5 years I've never been bitten by someone changing a core class that breaks my code. Maybe 3 times I've been bitten by someone changing a non core class, and it usually takes me about an hour or two to resolve it.

So that's maybe 6 hours in 5 years where I've lost time due to this, but the amount of time it has saved me is far larger than this.

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

#98

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…

This seems to be a bug in Google Groups -- if you have an expired session, it forces you to log in. But you were never signed in (or if you signed out) it doesn't ask and goes straight to the article.

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

#99
post #30

Earlier quoted context omitted.

We run probably one of the largest Ruby production systems that has ever been made and the dynamism and "monkey patching" are used daily to skillfully make the language better and better over time for the tasks that we solve. It's absolutely crucial to teams that internalize it's power and pitfalls.

"one of the largest Ruby production systems that has ever been made" As an aside, I worked on a very large Ruby app (built by about a dozen developers over the course of years) and then later worked on another very large Ruby app of similar size. One of the employees there remarked that it was the largest Rails app built. I think the people who write very large Ruby apps tend to be very quiet about it (no blogs, no o…

Lol, I work on a Ruby app that is entirely internal and processes an incredible volume of information. The key here was the ease of adding a few key C modules.

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

#100
post #84
post #42

Earlier quoted context omitted.

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.…

You can also make anything callable in Ruby: just provide a call method. The parenthesis will still work as may be expected in Ruby, but, as several folks said before: in Ruby parenthesis are not used to call anything. A method is called simply be mentioning it. Anything that follows is an argument and sometimes parameters are needed for disambiguation of the parameters. This is counterintuitive, only because it differs from most other languages. If you want to postpone evaluation, you have to wrap the method call in a closure that you .call later: in Ruby a method is not a closure and not a function pointer. It's different than in many other languages, but that alone doesn't make it inconsistent.
Post reply on HN