Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

djberg96
  (email not shown publicly)

Journal of djberg96 (2603)

Thursday April 11, 2002
07:51 AM

Ruby vs. Perl

[ #4114 ]
I like Ruby, but there are things that I've gotten used to in Perl. Little things. Things you don't think are such a big deal until they're taken away.

Take, for instance, each languages' implementation of GetoptLong. In Perl, the option specifiers are short and precise. In Ruby, they're rather long-winded. Also, Perl has plenty of config options, while Ruby has three: none, optional, mandatory.

Both languages assign the values to a hash...or do they? The Ruby GetoptLong class does not actually seem to be a subclass of Hash. It appears to be some bastard child of Hash, as it does not have all of the methods of the Hash class, while adding some custom methods of its own.

Ruby lacks the convenience I'm used to. For example, if I want to use a debug-print statement in Perl, I could simply do:

if($opt{d}){ print "Debug print\n" }

You would *think* that the equivalent Ruby code would work:

if opt['-d'] # or opt.has_key?('-d')
   puts "Debug print"
end

However, such is not the case. In fact, I don't know how to grab a specific option using Ruby. I can iterate over the entire object, I can pull single values in command line order, but I *can't* seem to specify a single value like that. The result is that I must assign values ahead of time in a giant 'case' statement. Yuck.

Oh, and one other thing. The ability to omit quotes in hash keys is something you don't miss until you're forced to do it in another language. Man, that gets annoying *fast*. I seem to recall that feature was added on a lark to facilitate Perl poetry (though perhaps that's a Perl 'urban legend'). Whatever the reason, thank you Larry for adding that!

Of course, it's very possible that I've totally missed something with regards to Ruby's GetoptLong. In any case, I think this is one instance where maturity trumps design.

PS - There is no GetoptStd in Ruby. Perhaps Matz felt it was redundant. :\

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Immaturity (Score:3, Insightful)

    by Matts (1087) on 2002.04.12 5:23 (#6903) Journal
    This is probably the main reason I'm still doing Perl coding full time instead of Ruby. While Ruby is significantly more elegant, easier to read, easier to write, and generally a better language than Perl, it's still quite immature.

    You miss CPAN *really* *quickly* when you try to use another language. And you don't realise just how complete modules like LWP and URI really are until you try to use the equivalent for other languages. Heck, even the horrible nasty File::Spec module is more complete than the equivalent in most other languages.
    • Hypothetically speaking, if there were an environment where something like CPAN were to exist, regardless of the language you were using (Perl, Perl6, Python, Ruby, Lua, etc.), would that make you more likely to switch to a new language?
      • Yes [*]. CPAN makes my job easier. It makes me look smarter and more productive for knowing about it.

        RAA (Ruby Application Archive) is almost there, it's just not automated in the same way.

        [*] The point being that Perl is a PITA for some things. Especially OO. And I like OO. I just don't like the whole "my $self = shift" crap that goes with it in perl. Every new OO module I write I feel like I'm re-inventing the OO wheel. Oh, and Perl is dying according to Simon, so I'm getting ready to jump ship.
  • if($opt{d}){ print "Debug print\n";

    Or with Getopt::constant [cpan.org], just
    D && print "Debug print\n";

    And since it's a constant, there's compile-time constant folding!