views:

5846

answers:

19

I'm a C(++)/C# programmer and I would like to learn a scripting language to create small tools (text processing, build scripts, a little web development, etc). I would like to learn either Ruby or Python. Is there a good reason to chose one over the other?

I looked at some sample code in both languages and they seem very similar to me. Maybe I'm missing something here? I also found the following comparisons:

Related

+1  A: 

For text processing and build scripts I think Perl would be the best, with second place taken by Python and third for Ruby.

But for the web development Ruby with Rails would be the best, Python in the middle and Perl last.

EDIT: One more thing - additional libraries:

  • Ruby has RubyForge and RubyGems - I think there is nearly everything you would need implemented.
  • Python comes with batteries included - lots of functionality works out-of-box. But I haven't found and good source for modules, nor system to manage them
  • Perl has CPAN - I think this is the best archive for libraries.
Migol
I'm not sure that Ruby on Rails is really that much better than Django (though I have no Rails experience, so I could be wrong).
Harper Shelby
Rails is far better in my opinion. I've used both. Rails allows for much faster development.
epochwolf
@epochwolf — Once you're familiar with it, perhaps. I found Rails to have a pretty steep learning curve. :-)
Ben Blank
I had tried to install aplication using Django and it was hell. No such problem with Rails.
Migol
Perl? That's so 20th century ;-)
vartec
Yepp, but it still kick ass when processing text.
Migol
If you want a list of python packages see PyPI (http://pypi.python.org/pypi)
Zoredache
web-dev with ruby, it's also : Rack, Merb, Sinatra, ...
Gaetan Dubar
I've used Rails and Django and I found that Rails is far, far better. Both for development and deployment. Django's automatic admin is nice though.
Jules
For build scripts you might like rake. Ruby's convenient regex syntax makes it very well suited for text processing.
Jules
Use virtualenv to manage modules (particularly application specific) in python.
DrBloodmoney
@Paolo Bergantino Could you add a bit more argument?
Amit Kumar
@Ben: Both Rails and Django have a fair learning curve. Considering what you get from them, I think they're both pretty reasonable.
Chuck
@Amit: All I can speak for is my own personal experience. I have a background in PHP/Perl/Coldfusion + your core languages (C++/Java) and I tried both RoR and Python+Django and I found Python to be more intuitive than Ruby. It blows my mind when people call RoR code 'elegant'. To me, its awful.
Paolo Bergantino
Nobody should have to learn Perl: Ruby and Python are both better for text processing than Perl.
Salim Fadhley
Uhm Salim, have you EVER used Perl or just looked at it?
Migol
A: 

Ruby is slower, but it have drb by default

Python is faster and have decorators

Some things is better in python, some in ruby, they are different

amirka
+6  A: 

Python is an older language than ruby. Older than java. Now it is more popular than ever. For these two reasons, I would prefer to learn Python.

EDIT: Python also has a good C++/C interface allowing for performance programming when needed. Ruby would have similar such thing, but is not as well-known.

Amit Kumar
Python 1991, Ruby 1995. I wouldn't say it is "much" older. But indeed, it is more established.
Antti Tarvainen
what on earth does "Ruby would have similar such thing, but is not as well-known." mean?? if you're a Ruby programmer the Ruby C API is known alot better than the Python C API !!!
banister
@banister Sorry that my statement is too vague. However I still feel there is an iota of truth in there. There are stardard APIs to embed python into C++, but swig is the only effective way to embed ruby into c++.
Amit Kumar
A: 

If you know the fundamental concepts of object oriented programming, then the only major difference between languages is the syntax. You shouldn't need to "learn" one or the other. You should be able to use whichever language is best for the task at hand. A few days with a reference book or web site, and you should be able to use any language.

Apreche
Learning a language is more than learning just the syntax. Its the libraries, the culture, the community and the philosophy. -1 NOT from me though.
Amit Kumar
I agree with what you are saying. Amit, I admit that you may be coding java in ruby, but, nevertheless, you will be using that language.
Geo
+23  A: 

I learned python first, Ruby much later.

  • Both are radically simpler than C++/Java (can't comment on C#, don't know it well).
  • Both add functional constructs, and constructs for elegant code lacking in the C's (decorators, closures in Ruby, map/reduce)
  • Both are dynamically typed.
  • Ruby is younger and maybe a bit more elegant, has a reputation for somewhat slower performance.

Coming from the Java land, the (conceptual) distance between Python and Ruby is negligible compared to the distance from java to either one. Both are very nice and well supported. It's probably impossible to make a bad decision here.

Steve B.
<sarcasm>...unless you choose Ruby</sarcasm> ;-)
Jon Cage
Ruby 1.9 ends the speed gap.
Nikhil Chelliah
"elegant" is highly subjective. I find it a bit baroque, compared to Python (But still like it a lot, nonetheless)
troelskn
Pedantic note: Python is trying to move away from functional programming, preferring equivalents such as list comprehensions.
Edward Z. Yang
@Ambush Commander: list comprehensions are functional too, just not from the Lisp family.
Nikhil Chelliah
+7  A: 

Python and Ruby are both effective for what you've described. Python has a larger user base, has more libraries, and more documentation. It's more likely you'll be able to find help with Python code if you run into difficulties.

They do have differences in style and attitude. For example, Ruby has code blocks while Python uses iterators/generators. Ruby people tend to do things like use Ruby's open classes which, while possible in Python, is frowned upon. It's partially a cultural difference - how important are the expressive needs of a single programmer over the cohesiveness of a group?

Me, I chose Python a long time ago, so I'm rather biased and stuck in my ways. ;)

If you were only doing web development then the weighting factors are different. There's a lot of information about Ruby on Rails, while the nearest Python equivalents (Zope and Django) don't have the same mind share.

Andrew Dalke
+16  A: 

Unless there is a specific set of libraries, or web development framework that you want to use, or other constraints which give one language a significant advantage in your environment, it's more important that you pick the language that you like best.

Advocates of each language will probably say theirs is better for this reason or that, but in most situations, it doesn't really matter. Both languages arguably have equal expressibility.

I personally prefer python. I like its emphasis on simplicity, readability, and a preference for the explicit over the implicit.

vezult
+1, though I prefer Ruby. :)
Sarah Mei
+1 from a fellow pythoneer - working out what you want to solve first would help the decision..
Jon Cage
+6  A: 

It really depends on the task. If I were you, I wouldn't be comparing languages - I'd be comparing communities. Instead of Python vs Ruby look at Django vs Rails. Look at python libraries vs Ruby gems.

I've tried both and coming from a .Net background I find python to be a much more natural language.

Horn
+12  A: 

One reason that a lot of people seemed to have overlooked is Antigravity! ;-)

More seriously though, I'd have to agree with those who suggested it depends what you want to do. If your focus is less web based I would be more inclined to recommend Python. It's astonishing how many modules are available, even for interaction with hardware!

When I was 'getting over' PHP I tried Rails because there seemed to be a lot of buzz about it at the time. Contrary to a lot of other people's experience (judging by the comments in this thread), I actually found Django far easier!

Ruby/Rail's talk of scaffolding and a whole host of other terminology I can't even remember now left me confused. I could see that if you got the hang of it there were some powerful techniques, but the barrier to getting something going and understanding it delayed me enough to try something else...

...enter Python/Django which somehow just clicked with the way my mind works. Python's syntax reads like english which is something I personally value really highly in a language. There's less quirky bits of syntax (compared to Perl or Ruby) - I suspect if you showed someone who'd never coded in either language, the Python code might more sense*. There's some fantastic resources to get you started in Python/Django such as The Django Book.

*Completely unqualified / subjective, but that's what I've taken from trying both :-)

Jon Cage
s/DJango/Django/
J.F. Sebastian
Antigravity is overrated.
greyfade
@Sebastion - thanks, corrected!@greyfade - have you tried it?
Jon Cage
The main advantage Django has over Rails is less "magic" - Rails encourages writing code that reads like English sentences, but leaves you wondering "How the hell does this work?" (with the community attitude seemingly being "Don't worry about how it works"), while Django doesn't get in your way and lets you dictate through Python how things should be accomplished; you can make it sound natural without hiding functionality behind layers of abstraction.
Wayne M
@Wayne; that makes sense to me and explains to some degree why I didn't get on with it as much; I've written code for a lot of embedded systems in my time as a developer so "magic" always causes me concern. A lot of tutorials I read for rails said things along the lines of 'just accept this for the moment - we'll talk about it later' for just about every aspect of description! The result leaves you feel rather dizzy :-)
Jon Cage
+1  A: 

I looked at some sample code in both languages and they seem very similar to me.

They are virtually the same, in what paradigms they support - functional, object-oriented, untyped. In my experience, Ruby handles string manipulation nicer (because of the syntax sugar for regex), while Python is easier to learn with better documentation and iPython. They vary a lot when it comes to philosophy of what kind of UI code should be, so it's probably best to start learning both and figuring out which style fits your personality better.

Andrey Fedorov
To clarify: Ruby and Python are not "untyped". They are both strongly typed dynamic languages.
dbyrne
As for string manipulation, compare `'привет'.capitalize()` in Python and `'привет'.capitalize` in Ruby. Python wins here.
Maxim Kim
+6  A: 

As a person who wrote code in both ruby and python, I would recommend ruby. Not that python is bad, but, ruby makes a lot of things easier for you as a coder.

The "magic" ruby uses is not cryptic, and it's something you can learn pretty fast. Pythonistas claim that their code is cleaner than other languages, the truth is that this is subjective. Personally, I hate python's magic/ugly underscore methods and passing self as a method parameter.

Both languages are equally powerful, and, let's be honest, since you are new to scripting, speed isn't your main concern. Already, ruby 1.9 is fast.

Geo
+2  A: 

The biggest difference is cultural, not technical. I'd play around with each and see which fits you better. The one thing I think ruby has going for it is jruby, which is a stable actively developed alternative implementation that opens many doors. At work I'm using jruby 100% of the time these days because we're using lucene.

jshen
+14  A: 

Ruby is a great language with one killer app which dominates the community: Rails. If you want to be part of that community you need Ruby. Rails dominates the Ruby community which is good because it gives Ruby developers some real focus, but not so good if you are not particularly interested in Web 2.0.

Python by comparison is far more mature and has libraries for just about everything you might ever one (I do scientific computing for Finance). It's just not particularly web-focussed. The nearest thing we have to Ruby (Django) is nowhere near as fully featured as Rails. The Python community is much bigger and has far more diverse interests.

It seems to me the choice is clear:

  • If your focus is building web-sites or web-applications go Ruby
  • If you want to do anything else, Python is probably the best bet
  • If you are not sure what you want to do Python is probably the best bet
Salim Fadhley
+8  A: 

Do the tutorials and decide for yourself.

Python: http://docs.python.org/tutorial/index.html#the-python-tutorial

Ruby: http://www.ruby-lang.org/en/documentation/quickstart/

If there is anything specific you can't figure out how to do in either language, just ask it here.

monkut
+2  A: 

Also consider the practicality of runtime issues for your environment. If you're going to want to run stuff on diverse OSes, (especially if you use a lot of non-core modules), you'll probably find that Python imposes less of a systems management tax.

For example, Ruby isn't a standard package on Solaris prior to OpenSolaris, and tools for creating standalone executables for Ruby seem a bit flaky to me (Perl's PAR::Packer still has them all beat :-)).

That said, considering just the language, I personally prefer Ruby.

robc
A: 

Using the rule of "excellence by association," Python is better because it is one of the three languages -- along with C/C++ and Java -- that Google uses for application development. The degree to which you agree or disagree with this answer depends on how much you trust the PhD's at Google to be smarter than all of us in not picking Ruby for app development.

Parvenu74
A: 

For your situation, someone who wants to sit down and start producing useful stuff quickly in both the short and long term, this is fairly simple. Use whatever people around you are using. Being able to poke your head in someone's office and get his help and feedback on a script is by far the fastest method of support. If it's someone in your company or workgroup, you'll probably be able to share code, as well.

The two languages themselves are similar enough that having that sort of support will make a bigger difference than anything else.

Curt Sampson
A: 

It really comes down to matter of taste, and perhaps, philosophy. For me at the moment I favor Python over Ruby, because I believe Python to be easier to learn and generally more readable. It's such a compact language that you can hold almost all the language features in your mind at the same time, which means that the language, as Bruce Eckel put it, "Fits your brain". This is important because we can thus focus more on IDEAS and CONCEPTS, the very essence of programming, instead of going to great lengths trying to stuff different versions of syntax into your mind.

Victor Yan
A: 

Definirely ruby. I myself learned ruby right after php. I look frequently. I even wrote few apps in python. But I always come back to Ruby...

Mantas