I have been a Python programmer for about 18 months, consisting of one internship and a few side projects, and I consider myself pretty comfortable in the language.

However, there seems to be a lot of attention on Ruby in the programming field, but not a lot on Python anymore.

So in learning Ruby, are there going to be Pythonic things that are just bad practices in Ruby? What should I watch out for, and what should I avoid?

  • 4
    I've always considered as a Ruby programmer if I should learn Python because it's all everyone talks about :P – Earlz Feb 11 '11 at 9:32
  • Despite the buzz it seems that Python is still used twice as much as Ruby (according to TIOBE at least -> tiobe.com/index.php/content/paperinfo/tpci/index.html). – Daniel Scocco Nov 25 '11 at 12:36
  • 10
    Instead of being a "Python programmer" or a "Ruby programmer," you should try to be a great programmer. Then, you can use whatever language you want and move on to new ones when the time's right. – BlackJack Nov 25 '11 at 13:12

I did Python back in 2003-5, when I was a Plone/Zope consultant. Then in 2006 I started picking up Ruby. I've never looked back. I think different people feel more comfortable with different programming languages and cultures, but for me, Ruby feels a lot better than Python.

I personally think that compared to Ruby, Python is the reliable workhorse that happens also to be a bit staid and bland. Ruby is a lot more fun. It's a prettier looking language, and can be made to do a lot of fun and funky things that keep wowing its practitioners. I've heard Python people attack Ruby for being too dangerous, saying that it's too easy to re-open classes and do wild and irresponsible stuff like that. But that's part of what makes Ruby feel like an action adventure comedy romance to me. Python, by contrast, is more like Ikea furniture: it's pleasant, comfortable, and reliable -- but it will never surprise you and take your breath away.

The two best things about Ruby, from my perspective, are the two things that distinguish it sharply from Python. First, Ruby is influenced a lot by Perl. Python seems to take pride in being the anti-Perl. But the stuff Ruby borrowed from Perl is of great practical value. Take regular expressions, for example. In Ruby, you can write regular expressions naturally, e.g. if mystring =~ /^\s+hello word!/ .... In Python, not so much, because Python is so anal about making everything follow a uniformly predictable syntax. In Ruby, you can get STDIN immediately with input = STDIN.read. In Python, you have to import sys and then sys.stdin.read(). These are but two examples where Python's effort to distance itself from Perl and be so predictably regular is trumped by Ruby's willingness to do what feels right in each case.

The other thing that distinguishes Ruby from Python is that Ruby is much closer to Lisp whereas Python is pretty much an imperative programming language. I think this is a big plus in Ruby's favor.

There many Lisp-like features of Ruby that make it possible to do more with less code in Ruby than in Python. For example, every statement and control structure in Ruby returns a value: you can get away in Ruby with never using the return statement. Even if statements evaluate to a value, so you can write stuff like this

result = if output == 'hello'
           [some code here]
           [some other code here]

In Python you would have to write

if output == "hello":
  [some code here]
  result = "world"
  [some other code here]
  result = "there"

Python makes you type result = twice. That's not very DRY (Don't Repeat Yourself). There are a lot of instances like this where Ruby will be more DRY than Python because of its Lisp-like qualities. Matz, the creator of Ruby, came from a Lisp background.

Some people say that Ruby also kicks Python's ass in metaprogramming (aka dynamic programming). Python people respond either by saying that metaprogramming is too dangerous, or by saying that theoretically, you can accomplish all the metaprogramming stuff Ruby can in Python, just differently. But one thing everyone does agree on is that metaprogramming is far less common in Python than in Ruby. And that's too bad, because metaprogramming is a trip.

I think it's probably true that at the end of the day Ruby and Python can both get the job done. Compared to C and Java, Ruby and Python are pretty much the same thing. They are expressive, productive, high-level languages.

So it boils down to your personality.

Do you like things to be predictable, regular, and safe? Do you like the imperative style of programming? Do you want to maybe work someday for Google? Do you think that Perl is a chaotic spawn of hell? Stick with Python.

Do you take great pleasure in finding the absolutely most concise way to accomplish some programming result? Do you get bored by regularity and uniformity? Do you like to have the freedom to write code in a style that is all your own, and have a lot of space to come up with your own cool tricks? Do you feel more of an affinity for Lisp than for C? Do you feel great admiration for Perl's epoch-making contribution to software programming, but only wish that it could be just a little less cryptic and ugly? Do you think of code like other people think of poetry? Try Ruby.

  • 11
    "And that's too bad, because metaprogramming is a trip" ... And just like a trip, it'll be great for a night, but eventually you wake up in the morning and forgot what you've done. I think metaprogramming is overemphasized in Ruby, and I prefer Ruby to Python. Most of Ruby's solutions to syntax problems is "you can get around that with meta programming" – Earlz Feb 11 '11 at 9:36
  • 23
    What? result = "world" if output=="hello" else "there" is perfectly valid Python (and three characters shorter). – Tim Pietzcker Feb 11 '11 at 10:41
  • 3
    @Tim OK thanks for correcting me. But can you do the same thing with an if/elsif/elsif/else statement -- i.e. if/elif/elif/else in Python? Can you do the same thing even if there are multiple statements inside the if or else clause? – dan Feb 11 '11 at 13:36
  • 1
    Wait, Python doesn't have a ternary operator? – PP. Feb 11 '11 at 13:37
  • 3
    "Matz, the creator of Python, came from a Lisp background." wait... AFAIK Matz is Ruby creator... – Eimantas Feb 11 '11 at 14:12

It depends.

For me python is by far easier to catch on than ruby, plus both language have a different purpose.

Python is more a classic language with a lot of low-level fancy things, keeping it clean and easy compared to C for example. Python doesn't have the ambition of Ruby, which to me has a lot more high level features.

It won't hurt you to learn Ruby, you will discover new things, but be aware than Python is closer to simple programming paradigms which made the success of C, with a lot of productivity boosters. Ruby is more for people who want to go further in programming concepts in general: Scheme and all those "superior" languages.


Short answer: Yes and yes.

Learning a new language is almost always useful, and it goes especially for Ruby since Rails is still very popular. And yes, knowing Python well will make it easy to pick up Ruby. They have some syntactic differences and different conventions in naming, but there's a lot of common ground too.

It's not a big time investment, and it's always beneficial to have more tools in your toolbox, so go for it!

(I've used Python for about 10 years and picked up Ruby last year. Currently working full time in RoR project)


Everything has a niche. For example Python (django) is a first class citizen in GoogleApp Engine, while it is the language or choice for many bioinformatic projects. Python does have a lot of market value (I get a number of unsolicited job prospects simply because I've done a lot with Python), but so does Ruby - in different areas. As you've no doubt heard here many times, it will always help you to learn more languages, so yes, learn Ruby. Will it be complicated? It'll be much less complicated than learning COBOL, since the languages and frameworks available are similar to one another. One example is Ruby's gems and python's pip.

Remember that languages are tools and every tool as a purpose. The more tools you know, the faster, more easily and more correctly you can build the treehouse.

  • I wanted to answer along the same lines, hope you don't mind the edit... – Dimitrios Mistriotis Nov 25 '11 at 12:25

Should I learn ruby ? Yes.

Learning a new language is always worth (especially if it enforces a different programming paradigm to the ones you know) and sometimes can make you more proficient even when programming in other languages. For example I picked up most of the functional programming I know from Lisp and I apply it when I need it to Python and Ruby.

Is it going to be difficult ? If you've learnt Python you can certainly learn Ruby too.

It's also useful if now you're looking for a job, it shows that you're curios about technology and that you can learn things on your own.

There's a good comparison between Ruby and Python on c2.com.

Not the answer you're looking for? Browse other questions tagged or ask your own question.