File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ruby and the fly likes Ruby vs other scripting languages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Ruby vs other scripting languages" Watch "Ruby vs other scripting languages" New topic

Ruby vs other scripting languages

César Guzmán
Ranch Hand

Joined: Mar 08, 2009
Posts: 32
Hi Gregory,
I would like to know what are the advantages of using Ruby over other scripting languages like Python, Pearl or PHP, etc. ?

Gregory Brown

Joined: Jul 18, 2009
Posts: 14
Hi César,

If you're talking about just doing some basic scripting, I don't think there is much difference across Python, Perl, Ruby, and PHP. I don't have extensive experience w. Python or PHP, but coming from a Perl background, I can tell you most of the sharp tools found in Perl can also be found in Ruby. As it turns out, Perl is faster than Ruby, so for the most basic things, Perl might be a better choice if speed matters.

The main difference I see is when a project grows beyond small one-off scripts into a complete application or library. When this happens, Ruby begins to shine (along w. perhaps Python) as a general purpose language that can pretty easily meet the needs of medium to large scale projects. Between Python and Ruby, the primary difference is in the object system. While Python's object system is sort of layered on top of the core scripting language in a sense, Ruby's is baked in, with the language being deeply object orient (in the Smalltalk sense) from the ground up. While Python may be a bit more mature than Ruby in some ways, most will agree that Ruby's object system is far more elegant.

Of these languages, while I think all have the ability to pass around anonymous functions, only Ruby provides code blocks as first class citizens. To see an example of these in action, check out this blog post:

Code Blocks - Ruby's Swiss Army Knife

So the main advantage of Ruby over PHP or Perl 5 is that it can handle complex object models without doing a lot of work to keep things clean. The advantages over Python are far more subjective, and come at a cost, so I think that choice largely boils down to personal preference. But of the 4, I personally think Ruby spans the greatest distance in potential purposes, from the most basic scripts to deeply complicated business applications. So if you had to learn only one, Ruby might be a good choice. But learning a little bit of each of them might be the best way to see for yourself what makes you happy.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

That is interesting what about the learning curve as compared to other languages

===Vyas Sanzgiri===
My Blog
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I, too, have limited experience with Python, a bit more experience with PHP - but from almost a decade ago - and very little experience with Perl. When I first saw Ruby code, I was immediately fascinated by how simple and beautiful the syntax was. Ruby code simply looked better than, say, PHP. While I was working with Python (a bit), I was also frequently working with small Ruby scripts and that parallel experience strengthened my feeling towards Ruby being my favorite. Technically, there wasn't much difference but the language syntax and the Core API were just so much better for my taste. Plus, the gem package management system made it easy to install libraries, etc.

As far as learning curves go, I'd suggest that Ruby probably has one of the easiest curves among programming languages.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Gregory Brown

Joined: Jul 18, 2009
Posts: 14
Vyas Sanzgiri wrote:That is interesting what about the learning curve as compared to other languages

I really can't speak for the other languages. I dabbled in Python very early in my programming career, so I'm sure a lot has changed since then, and I learned Perl so long ago that I can't really remember what it was like.
But when it comes to Ruby, it's actually sort of interesting. There is a pretty flat learning curve. Developers of all different skill levels and backgrounds will likely be able to get quickly up and running reusing the bits of knowledge they already have combined with some basic studying and effort.

However, Ruby is a deeply rich and powerful language. It'd be a disservice to yourself to just program in Ruby as if it were Perl, or if it were Java. Learning the roots of Ruby, especially the message based object system will really change the way you think about coding. For most people, crossing that bridge ends up leading to a temporary abuse of power, when you'll try to combine all the different things Ruby is capable of into your projects just because they seem exciting at the time. The hangover from that is often very unpleasant, as it takes learning just how much is too much before you begin to exercise restraint again.

But on the other side of that mountain, you'll find a remarkably powerful language that doesn't need to be inaccessible to mere mortals, so long as you exercise some thoughtful restraint while using the sharpest tools it has to offer. Really, this is what my book is all about. The sample does a good job of illustrating this sort of thing, so you might want to check it out.

César Guzmán
Ranch Hand

Joined: Mar 08, 2009
Posts: 32
Thanks for the tips,
it's really nice to know it's a good choice learning ruby while it's quite fast to learn, and talking about patters i can say GOF patterns can apply among many languages, as you said before, java patterns does not apply on other technologies they were created for an application container, it would be good to read the ruby patterns book to know a bit more on the subject.
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
I think you shouldn't lump PHP into the same pile as Ruby, Perl or Python. Its value outside its main use is very limited. Ruby can be used anywhere and for just about anything. The term scripting language doesn't really apply to it. It is the same with Perl and Python as well. It is as much of a scripting language as C, or Java is.

The only thing I remember from Perl is that it is truly a write only language.

Python is a lot more challenging to get into and is fairly inflexible, that is, adding something not intended is always an ugly hack. It rigidity makes it tougher to get into, and I have been writing Python code off and on for 5 years and I still am not used to lining up blocks. It makes it very annoying to add in(and remove!) a debug statement. When using Python OO, it is a horrible mess with all those selfs hanging around everywhere, this is one of the few places the java language is better(The java language is a horrible mess, although not quite as bad as C++, its true power lies in its libraries and JVM). Its main advantage has nothing to do with the language, and that is the performance that bytecode compilation brings. I am not sure it makes python worth using in many cases.

Ruby is a far more elegant then either Python or Java. It is also fun to work in, writing good java code is drudgery, ruby is just plain fun. A good example is to compare several Java based API's that try to mimic ActiveRecord to AR. They are all very clumsy and it has everything to do with the rigidity of Java. Rails is so slick because of Ruby. Once we can compile ruby code in bytecode happens, it will be interesting to see how it effects performance and usage of the language.

Patterns are almost completely language neutral, as it should be. Heck you can adapt just about any pattern to C or even assembly! That said a good Ruby pattern book is Design Patterns in Ruby by Russ Olsen, its main value is not the regurgitation of what the patterns are which were already done so well in the GoF book, but it shows how to correctly use Ruby's OO system.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
I agree. Here's the link:
subject: Ruby vs other scripting languages
It's not a secret anymore!