Live data from Hacker News

Ask HN: Why Python over Ruby?

news.ycombinator.com

151–160 of 198 posts

Re: Ask HN: Why Python over Ruby?

#151
post #117

Earlier quoted context omitted.

I have used both, Python more than Ruby. Python's iterators are more usable in many situations than the Ruby block system. I can return an iterator, stick it in a variable, call another function with it that returns another iterator, and so on. Python's classes also seem cleaner and less magical than Ruby's. For example, a method on a class is just an attribute that happens to be a method. Much more intuitive than Ru…

Ruby 1.9 has real iterators now.

They're in 1.8 now too:

    >> [1,2,3].each
    => #
    >> RUBY_VERSION
    => "1.8.7"

Re: Ask HN: Why Python over Ruby?

#152
post #103

Earlier quoted context omitted.

Well, I can answer at least a few of those 'WHY?!'s. Firstly starting with my_string['foo'] = 'bar', this is a syntax that is used a lot in Ruby for anytime that you wish to recover a subset of a collection - you can use it with a Dir object for example to recover a subset of directories/files, or in the case of a hash, to recover the object stored at the key. The thing is that you need to think about it as being a s…

I suppose these just seem odd to me, which was my point. Not that I find something absolutely wrong about them, anymore than I can find something wrong about a language which doesn't have mutable variables or whatever the case may be. A lot of Ruby's conventions simply scream "ambiguity" to me. A "subset of a collection" is extremely ambiguous; if there is more than 1 foo in my_string , does it always get the first?…

Perhaps there isn't a way to get the others, which I suppose would be in line with Python, which doesn't supply a string method to find all occurrences at once... but how do I offset it?

Yes, there's no way to get the other matches using [] as far as I know, it's just a generalization of being able to pass various types to it; Fixnum, Range, Regexp.. I don't see the harm in doing something with String too. If you wanted to extract multiple items, you'd use something like String#scan, or if you wanted to do a global replace, String#gsub, which can also accept a code block to perform computed replacements.

I can see where standardized methods like to_a can be more convenient, but they also open up the possibility for unlimited ambiguity. What does Foo.to_a do for your Foo class?

As of 1.9, it does this:

    NoMethodError: undefined method `to_a' for Foo:Class
In 1.8 it issues "warning: default `to_a' will be obsolete".

In Python, if I do `[foo]` Then foo is now a list.

You do the exact same thing in Ruby, though if you're wanting to cast your argument like the old to_a did, you use Array(), which won't turn [] into [[]]. If you want a number, Integer() or Float() will raise an exception if they can't give you one.

Re: Ask HN: Why Python over Ruby?

#153
post #100

Earlier quoted context omitted.

To claim that Ruby is a tangled soup of options and syntactic sugar is to miss the point really. What is the point? I sincerely wish to learn, for my own intellectual curiosity. Because I have read Ruby code and I have done Ruby tutorials and talked to people who use Ruby and for the life of me, no matter how hard I meditate on the issue, I cannot understand why anyone would use Ruby over Python. I don't feel Python…

I currently use Python and Django for the following reasons: 1) Coworker familiar with Python 2) I had an easier time understanding the mechanics of Django than I did Rails 3) Some libraries I needed were only in Python However, from a language point of view, I have a slight preference towards Ruby. Here are some things I like: 1) More consistent commitment to object paradigm, e.g. all function calls are actually met…

Humor me for a moment, because I've been asking this question of many people for a long time and have never yet gotten a straight answer.

Why is len() always the thing people pick on? Why is it always "Python uses len(obj) instead of obj.len()", and never "Python uses str(obj) instead of obj.str()", or any of the various polymorphic built-ins like sum()? I've seen this so many times now that I'm honestly quite curious about it.

Also:

"More consistent commitment to object paradigm, e.g. all function calls are actually method calls on an object."

Every function call in Python is always an invocation of a method on an object, even if it doesn't look like it. len(), of course, delegates to a method on the object. But even standalone functions are method calls. Try this:

>>> def add(x, y):

... return x + y

...

>>> add(3, 5)

8

>>> import types

>>> types.FunctionType.__call__(add, 3, 5)

8

The last couple lines there are what's really going on when you call the function.

(also, just as Ruby's "built-in" functions are really methods on Kernel which is made available globally, Python's "built-in" functions really exist in a module that's made available globally (and __builtins__ is its name)

Re: Ask HN: Why Python over Ruby?

#154
post #23

Python is older, and gained popularity before ruby. That's why it's more established outside of the web development frameworks space.

How does python compare to ruby in terms of web development? I get the impression that there are more 3rd-party libraries in Ruby, so it is easier to get web code up and running with ruby.

I think this impression comes from the culture of experimentation in Ruby and more widespread willingness to adopt new tools and libs very quickly. Python definitely has a diverse web development community and more options in some areas (like templates), but it's more conservative, not necessarily evolving as rapidly and, like Python overall, resists influence from other languages.

For instance, Haml and Saas are pretty widely accepted by Ruby web developers, whereas Django templates are very popular with Python web developers precisely because because they are close to straight HTML. Ruby developers (like Ruby itself) readily adopt good ideas from other languages, including Python (rack from wsgi, rip from pip, merb slices and rails engines from django apps), while anything that resembles anything from ruby or rails, like some Pylons components, gets criticized by many python developers. It's noticeable with version control, too, as svn is still very widely used by Python developers whereas Ruby and Ruby/Py developers moved completely to git and hg over a year ago.

Re: Ask HN: Why Python over Ruby?

#155
post #151
post #117

Earlier quoted context omitted.

Ruby 1.9 has real iterators now.

They're in 1.8 now too: >> [1,2,3].each => # >> RUBY_VERSION => "1.8.7"

They've been around for awhile

    >> RUBY_VERSION
    => "1.8"
    >> require "enumerator"
    => true
    >> [1,2,3].each
    => #

Re: Ask HN: Why Python over Ruby?

#156
post #142

Earlier quoted context omitted.

Python presented me with one insurmountable cognitive hurdle, and that's what drove me to Ruby: whitespace scoping. That single misfeature in Python is enough to keep me from ever using it in my own projects. The compiler/interpreter should work for me , not force me to work for the compiler/interpreter. (And no, there's not always preferably one way to do things, which is an attitude I can't stand.)

That's an ancient argument, about as old as the python language itself. The standard rebuttal for your particular argument would be: You indent your code anyways, in any language. Hence there is no extra work involved for writing Python. And yes, in this case that is the preferable way to do it. Unless you want to argue for non-indented or randomly indented code.

It's not an argument: it's why I don't use Python. No argument here, and nothing anyone says will convince me that the Python way is the right way at all.

And yes, I can easily argue for non-indented code for certain circumstances (print-debugging outdented so that it's more obvious to the eye when you're cleaning up the binary search prints that are surrounding your bug). Python doesn't allow those circumstances; it also doesn't easily allow for nicely embedded Python in templates.

There are definitely cases where indentation as syntax is the wrong choice, and my use cases tend to hit those. Thus, I don't use Python. If someone else find this misfeature to be a security blanket? More power to them. But not me.

Re: Ask HN: Why Python over Ruby?

#157
post #98
post #86

Earlier quoted context omitted.

How do you find Numpy/Scipy on Python compared to statistical languages like R? Also what kind of work are you doing?

I don't know about tel, but I use both pretty frequently (and usually together with rpy). R is great for some things, but I typically find that I need to use a general purpose language to acquire the data I'm processing. There are some processing steps that I easier in R though, so I offload things to that when it is more efficient. But for simpler things, I find that numpy is more than adequate for processing data t…

That's pretty much exactly how I feel.

I personally love R. More specifically I love how everything is implemented (at least sketchily) in it. Most specifically, I love how its plots look. If it could handle the large data sets I'm working with these days (MRI 3D+time images, sometimes multiple contrasts at once) I would use it a lot more.

So yeah, RPy is another big win for the Python side of things.

Re: Ask HN: Why Python over Ruby?

#158
post #15

Python is far more mature, isn't a strange ad-hoc combination of other languages, has a third-party library to do anything and everything (which is probably also reasonably mature), and doesn't have a community rife with arrogant children. I'm generalizing to some extent, of course, but these are the things that I and other developers I know associate with Ruby (including many who's startups are built on it). I imagi…

"Python is far more mature" How so? It's mot like Python is 10 or 20 years older, so how do you determine the "far more" part? And of what value would this difference in maturity be? COBOL is "far more" mature than Python. Is that a big win for COBOL? Once a language reaches some reasonable age and general wide-spread usage, points about maturity seem silly. (On reflection, I suspect you're just trolling.)

In programming languages, like people, maturity is a function of more than just chronological age.

Re: Ask HN: Why Python over Ruby?

#159
post #118

Earlier quoted context omitted.

So I just saw 3 ways to print from 3 to 6... are those all used in the wild? Zen of Python: "There should be one-- and preferably only one --obvious way to do it." Sure, there are other ways to do it in Python, but it'd be frowned upon to use something like 3.upto(6) rather than a standard range() that everyone is used to. Readability matters.

I like the Zen of Python myself, but the first thought that crossed my mind was that the Python example could use xrange and save the generation of a temporary list. So there are at least two ways of doing it in Python, both of which look very similar and differ only in the underlying implementation. This makes me curious how much more frequently range is used than xrange and in what situations it's preferable.

This is an acknowledge minor "wart". In Python 3.0, range() does the same thing as xrange().

Re: Ask HN: Why Python over Ruby?

#160
post #100

What's clear to me reading the comments in this thread, is that there are a lot of people who like Python, and don't understand what people appreciate in Ruby. None of these are reasons why people choose Python over Ruby. Or why Python has become more popular. It is worth noting that Python was also mentioned a lot as a teaching tool when its popularity began ramping up, and some universities have replaced Java and S…

To claim that Ruby is a tangled soup of options and syntactic sugar is to miss the point really. What is the point? I sincerely wish to learn, for my own intellectual curiosity. Because I have read Ruby code and I have done Ruby tutorials and talked to people who use Ruby and for the life of me, no matter how hard I meditate on the issue, I cannot understand why anyone would use Ruby over Python. I don't feel Python…

Ditto. The syntax seems cluttered more cluttered with sigils (some optional), and much of it seems merely to support things that Python does much more readably.

I occasionally tangle with a friend who is a Ruby fan, and who tried Python back in the 1.4 or 1.5 days and gave up on it. He still hasn't delivered me any solid reasons for trying out Ruby.

It is entirely possible that neither language presents sufficient relatively advantage compared to the other to persuade an expert in either to switch. The only exception would be due to a 3rd party application or library that is only available in one of the languages. (For instance, I work heavily with numpy and scipy; I'm not aware of Ruby equivalents.)

Post reply on HN