+5  A: 

I'm more of a Python than a Ruby programmer but it boils down to the following points.

  • Personal preference (programming style etc.)
  • Problem you're trying to solve (availability of libraries etc. is important here).
  • Integration with existing code bases.

That being said, I have a few reasons that are technical because of which I use Python over Ruby. These are personal opinions and not unbiased.

  • Ruby was an underdog till Rails came along. And from what I hear, Rails isn't all that hot. The language grew because of a killer app rather than it's own virtues. The rails community is from what I've seen quite abrasive.
  • The Ruby Standard library documentation is much poorer than the Python one.
  • Till recently, the Ruby interpreter (MRI) didn't have byte compilation and was quite slow.
  • Python's emphasis on readability rather than "clever programming tricks" makes for clean code which is easily understood (very little magic - I say this after a couple of years of bad perl).
  • I really don't like the @@ etc. sigils to denote things.

Just to balance it off, here are the things I like about Ruby (with my limited exposure).

  • The whole yield coroutine thing. It's there in Python as well but not as deeply as it is in Ruby.
  • The metaprogramming.
  • The emphasis on tools and processes in the community (although it does sometimes become overkill).
Noufal Ibrahim
Downvoting is not equal to disagreeing. If there's a disagreement, discuss. If the answer is of low quality, downvote. Why do people downvote without a reason?
Noufal Ibrahim
1. Noufal, it's irrelevant how each language came into popularity. 2. The 'yield' in Ruby has nothing whatsoever to do with coroutines, it's merely an invocation of a lambda.
banister
It's not irrelevant. A language pushed by a corporate entity (e.g. Java) is not widespread purely because of it's technical merits. Of course, my evaluation might be wrong. As I said, it's a personal opinion but it's definitely not irrelevant.
Noufal Ibrahim
Apropos yield, perhaps not *exactly* coroutines but the transfer of control between the "yielder" and the code block in question is quite similar to the way coroutines work. Anyway, it's the behaviour and usage of `yield` that I'm interested in.
Noufal Ibrahim
@Noufal, the question was about the advantages/disadvantages of the language. Whether or not Ruby became popular due to rails or someone waving a red flag above their head is beside the point. A closer analog to co-routines in Ruby 1.9 would be fibers. Invoking a lambda (which is what a `yield` really is) is not at all the same thing.
banister
My experience with ruby is limited compared to my experience with Python. It's reason for adoption is, in my opinion, a valid metric. Perhaps not about the language per se. But definitely about the ecosystem as whole. As for your comments on `yield`, I stand corrected. Thanks.
Noufal Ibrahim
+3  A: 

Python is more like Java - it's a bit more verbose, but it drives you towards a better design.

Ruby is more like perl - it's a little complicated, and sometimes it's almost magic, but you can make it do some very cool stuff if you know how. Built in regexps are cool.

wisty
Python is *more* verbose than Java? That's not really true. A Hello world program should be enough to show the difference.
Noufal Ibrahim
@Noufal: I think that wisty was referring to Ruby, not Java: "Python is a bit more verbose than Ruby."
EOL
Ah okay. I misunderstood. Python can be more verbose than Ruby/Perl. That's true.
Noufal Ibrahim
@Tim, Regexes in Ruby 1.9 (which has been out for more than a year) support lookbehind.
banister
@banister: Thanks for the info, will retract my comment :)
Tim Pietzcker
Yeah, I think Pythons a bit more verbose than Ruby. No way is it more verbose that Java.
wisty
A: 

I like Ruby because of the way it handles blocks of code. Let me show you an example:

def time_it(meta_data, &block)
  now = DateTime.now
  yield(block)
  later = DateTime.now
  @results << {:meta_data => meta_data, :time => ((later - now) * 86400.0).seconds}
end

time_it :function_name => "blah", :some_other_info => {} do
  # put some code in here and find out how long it takes.
end

Sometimes I like to benchmark something (usually just for fun) and so I wrote a function that wraps around some block of code and times how long it takes. In any other language you might have to copy,paste...copy,paste around your code to get it to do the same thing.

missing_methods is also another cool feature of ruby that makes Rails super useful. The idea that you can make SomeModel.find_by_some_column_and_some_other_column(some_column, some_other_column) work magically really blows me away. Everything is an expression (with only a few exceptions to this rule) so it makes programming in ruby a lot more intuitive then some other languages. If you need to add a custom method to a class or even to one instance of that class, you can do that fairly easily with Ruby.

The ActiveRecord design pattern is being implemented in other languages now like C# so a lot of what makes Rails really cool is making other languages appealing again, but since using Ruby, I haven't wanted to go back to those other languages. To me, Ruby means freedom... hopefully that's not too cliché but I wish people interested in programming were introduced to Ruby before they are introduced to C/C++ because I think it would make them better programmers (although learning to manage your memory is a really good thing to know!)

EDIT: Here's another Ruby code example of how it deals with arrays that I thought was pretty kick ass and have never seen in other languages:

a = [1, 2, 3, 4]
b = [3, 4, 5]
a - b
# => [1, 2]
b - a
# => [5]
DJTripleThreat
How does Ruby compare to Python, on these points? For instance, the Ruby array example that you give can be done similarly with Python sets…
EOL
your invocation of the `time_it` method does not require `{}` around the hash parameter. It also looks much neater if you leave them out. (see Rake). Also `method_missing` is implementable in Python.
banister
@bainster: code edited. Yeah, I don't use Python so I can only say what I like about Ruby.
DJTripleThreat
@DJTripleThreat: but the question wasn't 'what do you like about your favorite language' it was 'what are the advantages/disadvantages of one with respect to the other'. I like Ruby a lot, but your answer does not address the question particularly well (excepting your comment on blocks, which python does not have)
banister
I guess thats why I got a bunch of upvotes for my answer then.
DJTripleThreat
DJTripleThreat: actually if it wasnt for my upvote (which i cannot now retract for some reason) you would only be on 2 and if i actually downvoted you (which you actually deserve) you would be on just 1 point :)
banister
Wait why would you upvote my answer and then bitch about it?
DJTripleThreat
@DJTripleThreat: because i made a mistake, i misread your answer. :)
banister
@banister: I don't think that this answer deserves a downvote (if only just for mentioning code blocks), but I'm sure you can retract your upvote.
ΤΖΩΤΖΙΟΥ