Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Me too, but I don't think it's just a preference. I come from a C/C++ background (I'd say the majority of people do, or C# or Java), and Python looks much more familiar and obvious to me than Ruby.

For example, this from Wikipedia:

  (3..6).each {|num| puts num }
Has some funny brackets and pipes. In Python, it's much more familiar to C-ish folks like me:

  for i in range(3, 7):
      print i


Ruby's syntax is flexible:

  for i in 3..6 do
    puts i
  end


Very flexible. Once you learn what the sytnax means the implementation of blocks and iterators is one of the best parts of the language.

    3.upto(6){ |x| puts x }
I don't think the uniqueness of a language is any reason not to learn it. To be honest that sounds lazy.

PS I'm not a Ruby zealot, and Python is a great language


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.


While I agree that readability matters _a lot_, the "Zen of Python" honestly bugs me. But maybe it's just the counter-culture ethos that dwells inside me. +)

Note: I used Python daily at work and for open source projects. I also use Ruby for open source projects. I like them both.


I'd argue 3.upto(6) is much more readable and obvious than range(3, 7). Even just on a conceptual level, Python requires a degree of translation and its stop argument is not intuitive whereas even someone who has never programmed before can understand the Ruby.



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


I'm sorry, did you say there's only one way to deal with each integer in a set of numbers? Admittedly I don't know very much about python, but it seems that at the very least you could do this recursively.


Neither Python nor Ruby AFAIK have tail-call optimization.


You're right, that's pretty C/Python-like. Nice. In fact, I've often thought that Python could make the syntax "n..m" expand to "range(n, m+1)" or equivalent.

However, Python's TOOWTDI comes to mind. Not that it's quite true, but probably closer than with Ruby. I guess one could debate whether TOOWTDI is a good thing -- but I reckon Perl is the argument as to why it is a good thing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: