I'm a Ruby programmer. Recently there was a poll about everyone's favorite programming language and Python came out ahead over Ruby. To me, Python seems to lack some of the niceties that Ruby has like blocks and it also seems to have some superfluous stuff like having to pass self into each method. I'm not trying to ignite a flamewar but rather I am genuinely interested in why a programmer might prefer Python. Thanks.
I've done some programming in Python and am currently learning Ruby.<p>One of the differences I see is Python's philosophy of having one, correct way to do things, while Ruby supports having multiple ways. This difference in philosophy seems to be clear in the language design. Python usually has one or two accepted ways to do basic tasks, while Ruby has more.<p>It's a little frustrating because in Ruby, I have to remember different syntax and constructs for doing the same basic thing. I'd much rather just have to remember one way, and expect other people's code to use that one way (ie, Python is more readable).<p>Python also seems to have a larger community and more well-developed/useful libraries and tools. I don't think NumPy and SciPy have equivalents in Ruby.<p>Also, even though Ruby says it advocates the principle of least surprise, I'm often surprised by Ruby, and much less so by Python.
I'm going through Ruby koans right now but am a Python programmer.<p>The #1 thing I like about Python is the community and has nothing to do with the language. I find the python community doesn't actively champion the language as the end all be all (for better or worse). Rather it is accepting of when Python sucks for a specific task.<p>I also find Ruby to be really web focused. Python tends to have lots of libraries that are not solely for web based needs. Not to say Python doesn't have web stuff...there is so much I can't even keep up.
As a scientific programmer, I like python because I'm used to it, because there are a wealth of useful libraries and packages that suit my needs, and that it can be "fast" (if you know how to take advantage of the underlying c code and use numpy whenever possible; and the obvious fast-prototyping advantage over compiled languages). I don't have much experience with Ruby so this is by no means a diss of the language. Its just why I have stuck with it for so long
Disclaimer: This is very subjective and from a Python guy<p>1. While Python and Ruby are roughly of the same age, Ruby was only popular in Asia before Rails. At that point Python already had a solid base of non-web stuff.<p>2. Ruby feels more wild and crazy to me. Is monkey-patching still considered cool in the Ruby community? As a Pythonista I try to avoid such confusing stunts.<p>Due to both of those reasons I believe Python has more solid libraries. For example, Rails was extracted from a small productivity app, while Django was extracted from a serious newspaper website. While Ruby was fixing memory leaks, the Python interpreter was speeding up its hash map.<p>As a language enthusiast I envy Ruby for the blocks. As a Python programmer I never felt the need for them.
One word: Cython.<p>Having a fast way to interface C code, and speed up your bottlenecks is a godsend for anything that isn't a strict web app.<p>I'm sure Ruby has an FFI, and most likely even has a SWIG interface but Cython is far beyond that--its a typed version of Python that compiles directly down to C/C++, so you can port code between Python and Cython instanteously.<p>Doing just that usually makes it 2x faster.
Annotate it with types to make it more than 10x faster.
Change the algo to something you can only do efficiently in C, and it's 100-1000x faster. Seeing something go from taking 10 minutes to taking 600ms in less than a days work is fantastic.<p>----<p>Also personally, I find I like white-space scoping. Python is like psuedocodethat actually runs.
I like Perl, I like SmallTalk, and given that, I actually do like Ruby the language. My main peeve is the infrastructure. No, not even the community, you'll find nice people and bumwads on both sides. But I just can't stand the penchant for overly cutesy DSLs that seems to pervade the Ruby world. It's basically Lisp macro abuse all over again.
I know that you are asking why Python might be better for some uses, so pardon a little tangent:<p>About 7 years ago I tried really hard to get into Python because someone I know at Google really liked the language, and I needed to pick up a better scripting language (I dislike Perl). I used Python a lot for about a year, reading a few books, using it for a lot of small projects. Python was nice!<p>Then I started looking at Ruby, and for me it was programming language love at first sight. I can not justify my strong preference for Ruby on technical grounds, rather I simply prefer it. Ruby is no longer just a scripting language for me (although I write a <i>lot</i> of 20 line Ruby programs just to get stuff done).<p>So, I would argue that you should choose either Python or Ruby based on your personal gut feel, after spending time with both languages. The only exception to this advice is if you want to work for a company that prefers one over the other.
Readability. If I'm working in a team, it's generally the <i>number</i> <i>one</i> concern for any language I'm using, but even if it's code that I know nobody else will ever touch, there's a great comfort in knowing that I won't have to spend too much effort figuring out what I was thinking when I'm reading year-old code.
One point is that the python eco-system covers a lot more ground. Ruby and the ruby eco-system basically only focuses on web development, if ruby has other strength the community is pretty quite about it.<p>Python is also pretty good at web development, but is also excellent at scientific computing and visualization, data processing, statistical analysis (including nice bindings to R), network servers using twisted, natural language parsing, GIS analysis, computer vision and image processing and so on. Python also has Cython which makes it trivial do use C to speed up crucial functions.<p>Basically I prefer python because I can use the same language for everything I need and want to do.
I think it has nothing to do with the languages themselves, and more to do with a sort of tipping point around tools, libraries and adoption. Through random chance, I prefer Python simply because people I know use Python so I started to use Python.<p>At the end of the day, there really isn't much inherent that makes Python better than Ruby. Which is exactly why the world would benefit from the eventual dominance of one over the other. Even if it is a randomly driven tipping point process.<p>On the other hand: Ruby vs Java vs C++, each has clear advantages in certain situations. These languages seem less likely to compete with each other.
I am not sure that this poll was representative of the whole programming community. We are a Berlin based startup and we're looking for a Python developers and they are a lot harder to find than Rails devs. Not to talk about PHP, C# and Java developers.<p>Also there are tons of existing libraries and you don't have to implement anything but your actual business logic.
When I was starting learning Python, I considered Ruby. At the time, Ruby was Active Record only. Active Record does not let you use SQL procedures without defeating the whole purpose of Rails. For me, it meant that Rails was only good for toy CRUD apps.
The opening of classes seems to cause people problems. A lot of Ruby's popularity is from it's killer app, Rails. But trying to program python after Ruby for me is difficult, python feels so constrained.
Well, for me, it's readability and maintainability. I find Ruby unreadable, and if I want to hire a programmer, it's easier to take a Perl, PHP, or even C# developer and teach them Python than it is to teach them Ruby, at least from my experence.<p>I don't think there's anything wrong with Ruby as a language, and until it was added to most languages, the scaffolding held me in awe...<p>I just prefer Python's readability.