Forgot your password?
typodupeerror
User Journal

Journal Journal: Drug patents threatening cheap drugs

This was a story I tried to submit but was rejected by Slashdot's editorial staff. Not grousing, saving my composition here for posterity, as I do with other of my rejected stories.

Comment Ruby vs. Perl vs. Java (Score 1) 325

I haven't explored Ruby much, but as I read through each of the features touted the article, one thing that came to mind was how similar many of them are to Perl both in syntax and in usefulness. (Background: generally I use Java at work and LAMP(erl) for managing my own websites.) So let's do a little closer comparison of the three languages. If any Ruby experts want to jump in and correct anything, I'd be interested in hearing it.

  • Fast moving objects: All constructors essentially similar, using new classname(params) or some permutation thereof. Ruby has C++ style default values. In Perl you have to remember to bless(), but only in the constructor.
  • RubyBeans: Ruby definitely has the most compact property notation. Java is verbose but predictable. Perl is weird, with $obj->{prop} syntax or the use of tie(), and read vs. read-write isn't as easy to do.
  • Collections: Perl and Ruby both define lists with [...] and have [n] and [m..n] accessor syntax. Java, well...
  • Iteration: collection.each { |var| do something with var... } looks a lot like foreach $var (@collection) { do something... }. With Java 5, at least you have for (var in collection) { do something... }
  • . But this is probably the most important operation that needs a compact syntax!
  • Yes, yes, yes: Ruby has a while() construct, but the author claims that it's not much used due to the .each syntax. Not so sure I agree - I find while is best for looping when the termination status is calculated in some way.
  • Conditionally yours: postfix if statements - first saw it in Perl and hotly debated ever since. But it's no worse than the "optional braces" that derives from C. Perl and Ruby both have unless.
  • Polymorphism and Mixins: Match up those method names! Perl and Ruby are again similar. Ruby has mixins, Perl has @ISA. Ruby seems slightly more elegant, but the end result is pretty much the same - I don't how there's more than one sensible way to do OO in a dynamically typed language (no, I haven't seen Smalltalk).
  • Regex: var =~ /expr/ in both Perl and Ruby. I don't know whether Ruby has regex flags to compare with Perl. Java 4 regex package has a completely different syntax but is pretty compact and easy to use, though.

Syntactically, Ruby seems to be much closer to Perl than Java - this feels like a apples-and-oranges article. I know Java and Perl both compile to bytecode, both approach native speed in practice, and both have a extensive set of libraries. I would only assume that Ruby is the same.

I'm sure I'm missing many of the intermediate-to-advanced features of Ruby, but what would make me choose Ruby over Perl? Anyone else feel like diving in?

Slashdot Top Deals

Porsche: there simply is no substitute. -- Risky Business

Working...