From: David Masover Date: 2009-02-10T03:15:25+09:00 Subject: Re: Ruby vs Perl performance Robert Klemme wrote: > Yes, you can program OO style in Perl and there is /some/ support for > this - but it does not really give you much advantage over doing OO in > C (yes, you can do that: even std libraries do it, see open and fopen > et al). > I haven't done enough C to say for sure, but I loved Perl's OO. There definitely seems to be more there -- inheritance via @ISA, constructors via bless -- and while some find it ugly to expose all the underpinnings, that is one thing I love about Perl. It's also one of the same reasons I love Ruby -- I don't have to get my hands dirty. Take the simplest example, a method. In Ruby, it'd be: class Foo def bar(arg) ... end end In Perl (and forgive my syntax, it's rusty), it'd be something like: package Foo; sub bar { my ($self, $arg) = @_; ... } Now, the Ruby version is much more readable to me, and much easier to work with. But there is something magical about the way the Perl version starts from even more basic primitives. Arguments are simply passed in as an array, which you can either unpack or not, as you like. The current object is passed in as an argument, meaning this is just another subroutine -- it lets you do tricks like this: my $foo_like_thing = Bar::new(); Foo::bar($foo_like_thing, $some_other_arg); Kind of like Javascript's call() and apply() -- and I'm not even sure this can be done in Ruby. For all the duck typing goodness, I can't seem to figure out how you'd unbind a method and rebind it to something of an unrelated class, unless there's an explicit tree of inheritance. Not that this is something I've often (ever?) felt the need to do in Ruby. I'm just using it to illustrate what I like about Perl -- that it's so completely relaxed about this kind of thing. It gives you the bare bones of what's necessary for an object system, and you build whatever you want on top of it -- even with the guts exposed all over the place. > IMHO the best arguments for Perl are these > - often it's installed on a *nix system > - CPAN I'll agree with that. And for new projects, I will instinctively choose Ruby. But it's for other reasons -- I like Ruby's syntax, and I like everything being an object, and being able to do things like the Rails Object#blank? hack, and iterators, and...