|No such thing as a small change|
Ruby Before Perl? Nah.by starX (Chaplain)
|on Jun 03, 2008 at 20:10 UTC||Need Help??|
A recent project I've been working on has brought me into more intimate contact with the Ruby programming language than I have had before, and as I take a moment to return to maintaining some Perl apps I've written, I thought I might share some of the the thoughts that came into the head of this Perl programmer as he delved into Ruby for the first real time.
I don't mean this to be a exhaustive list of differences, a detailed technical comparison, or an introduction of Ruby for Perl programmers. Just a gathering of thoughts that I feel the need to share.
What a Dump!I see it time and again: people dismiss Perl as ugly looking and hard to maintain. As we all know this is because Perl lets you do all sorts of elegant things; whether or not you should is another matter, and Perl Best Practices stands as a very nice guidebook of do's and don'ts. I know my code certainly improved after reading through it.
Ruby seems to escape this criticism, and yet it can be every bit as ugly. A lack of curly braces around definitions takes some getting used to, and it makes a poorly indented application hard to read at a glance.
Another big departure was in the lack of line separators (;), or perhaps I should instead say that they're optional. While I can see the argument that this forces readability via-a-vie a one line, one statement structure, the fact that line separators can be used removes this benefit.
Lesson: You can make Ruby every bit as messy as Perl if you want to.
OOPs and InfrastructureHere I see a very clear benefit to Ruby. No doubt this speaks more to my abilities with the language, but I learned Object Oriented programming with Java, and moving into that particular area in Perl was cumbersome.
Ruby, on the other hand, is OO from the ground up, making it more friendly to the Java trained OO programmer. Or at least to this one. Ruby takes it a step further though, and does away with primitive types, and the result is some very clever infrastructure. An array variable, for example, is an instance of the Array object, and contains useful methods for working with the array; iterators, for example. Hashes work similarly.
From this Perl programmer's perspective, it takes some getting used to. Instinctively one wants to write
Then again, that's a habit that one learns to change. Which brings me to the next item.
The Variable Appearance of VariablesPerl programmers have got used to being able to tell what they're looking at at a glance. $scalar, @array, %hash are all great ways of being able to figure out what sort of data you're working with at the moment. No looking back to see if c was declared as an int, a char, or a float. Easier to keep track of what you and other people are doing.
Ruby doesn't use this convention, and boy did I miss it. The @ character makes an appearance to signify
Also, it helps you appreciate one of the ways that Perl is more readable than its counterpart.
Testing and Documentation.Perl and Ruby both provide excellent testing and documentation facilities. Where Perl has POD, Ruby has RDoc. Where Perl has Test::More, Ruby has test/unit. Both are invaluable tools if used properly, and it's worth taking the time to get to know how to used them.
Community SupportThere is no CRAN, and there are no Ruby Monks. That's not to say that Ruby doesn't have it's own module system (rubygems.org), but it's nowhere near as robust as CPAN. Likewise, I managed to find some folks to answer questions I had in irc, but Perl monks it is not.
This is, I think, a reflection of the relative maturity of Perl to Ruby. With
ConclusionsRuby is an excellent language, and I'm interested/eager to learn more about it. With a variety of Ruby related modules on CPAN, interoperability between the two languages doesn't appear to be out of the question. It seems to me that Ruby will make a better choice for OOP when it's called for, and can be an excellent way of rapid prototyping class hierarchies before developing them in another OO language.
That said, I've always believed that the strength of any organization is in its people. Perl provides the model of a development community that other languages strive for, and as a result, when I'm presented with a task that seems unusual, awkward, or that requires fitting the square peg in the triangular hole, Perl will continue to be the natural choice.
Update: Thanks to the monks who have corrected some of my errors. I have made changes in the above text that incorporate their edits, while leaving the original incorrect data present and struck through.