
Why do programmers prefer Python over Ruby? - daviddavis
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.
======
dwong
I've done some programming in Python and am currently learning Ruby.

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.

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

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.

Also, even though Ruby says it advocates the principle of least surprise, I'm
often surprised by Ruby, and much less so by Python.

------
jtchang
I'm going through Ruby koans right now but am a Python programmer.

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.

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.

~~~
LoneWolf
I have that same feeling about the ruby comunity and its the main reason why I
try to stay away from it, it gets on my nerves. About the python comunity, no
complaints so far with one or two exceptions. I also feel the same about ruby
being more web focused, it may be wrong but that's how I see it too, one
"problem" of python is that there is too many modules and with some variations
so its rather hard to know it. And maybe its just me but the python docs
sometimes are rather confusing, with few examples (I like to read examples,
its a lot easier IMHO)

------
schrodingersCat
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

------
beza1e1
Disclaimer: This is very subjective and from a Python guy

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.

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.

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.

As a language enthusiast I envy Ruby for the blocks. As a Python programmer I
never felt the need for them.

~~~
Wilduck
> As a language enthusiast I envy Ruby for the blocks. As a Python programmer
> I never felt the need for them.

I think one of the reason why Python isn't hurt by the lack of blocks is the
difference in namespacing rules. Since defining a top level function doesn't
pollute the global namespace, there's much less of a need for blocks and
mulit-line lambdas. If I feel that I've got too many functions sitting around
in one of my project's files, I can simply open up a new file, utils.py, and
all my utility functions will be in their own namespace.

So, I agree, blocks are cool, but when it comes to re-reading code, I like
that I've been forced to spend the extra few seconds to give my functions
names.

------
true_religion
One word: Cython.

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.

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.

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.

\----

Also personally, I find I like white-space scoping. Python is like
psuedocodethat actually runs.

~~~
rmk
Hmm... Could you recommend some resources for this? I need to wrap a couple
libraries and make them accessible in both Python and Ruby.

~~~
synparb
The best thing to do is to take a look at the Cython docs
(<http://cython.org/>) and check out some of the whitepapers they have posted.
There is also a bunch of cython code on github. If you search "cdef extern"
you should find examples where other people have wrapped external c libraries.

~~~
rmk
Thanks!

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

------
mark_l_watson
I know that you are asking why Python might be better for some uses, so pardon
a little tangent:

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!

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 _lot_ of 20 line Ruby programs just to get
stuff done).

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.

------
bmelton
Readability. If I'm working in a team, it's generally the _number_ _one_
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.

~~~
nwmcsween
This is moot you're not writing a low level math library nor are you using
some archaic programming language, readability is relative and it's between
the chair and the keyboard that defines that value. You can write unreadable
code in python just the same as you can in ruby.

~~~
bmelton
You're right in a sense, but I strongly disagree.

The trick is to write readable code, and Python encourages that at every step.
The Python mantra is "don't be clever". Compared to Ruby, where developers
routinely vie for the most clever way to do something that may or may not (and
usually isn't) in the interest of readability.

Also, the significant whitespace enforces the readability of Python vs.
something like Perl, which is a very information-dense and, in the opinion of
myself and many others, a substantially less readable language.

Either way, for my money, having used both languages extensively, Python
proves to be more readable over the long haul. YMMV.

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

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.

Basically I prefer python because I can use the same language for everything I
need and want to do.

~~~
bowyakka
I would second this, in my $DAYJOB which is focused on building search
engines, python is one of the goto languages alongside R for doing a lot of
exploratory stuff.

Sure ruby could, but it would have to play catchup adding things like sage,
cython, numpy, scikits etc etc

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

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.

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.

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

Also there are tons of existing libraries and you don't have to implement
anything but your actual business logic.

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

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

------
shawiz
Python is a lot easier to learn than Ruby, therefore there are more people
know Python than know Ruby. The poll just shows the demographics.

------
arjn
I came from a java background. I like Python because I feel like I think in
python and it makes me write elegant (IMO) code.

------
shortfold
because FUCK RUBY (c) the black guy at security conferences

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

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

I just prefer Python's readability.

~~~
canatan01
I agree. I am a PHP developer and just started learning Python a few days ago
and must say, for now, it is indeed easy to learn and is very readable. Though
I never tried Ruby so I can't tell you if I would find that easy also.

