• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ruby vs other scripting languages

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregory,
I would like to know what are the advantages of using Ruby over other scripting languages like Python, Pearl or PHP, etc. ?
 
author
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is interesting what about the learning curve as compared to other languages
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gregory Brown
author
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

-greg
 
César Guzmán
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic