http://www.perlmonks.org?node_id=690780


in reply to Re: Ruby Before Perl? Nah.
in thread Ruby Before Perl? Nah.

Not that this approach doesn't also have issues (e.g. you call method zorch expecting the object to do foo, but instead it does bar and wipes your hard drive . . .), but there is a rationale behind it.

I'm used to seeing posts like this explaining Ruby's object system when it's being contrasted to C++ or Java, but is this really noticably different from Perl's OO system? How does foo.zorch in Ruby differ from $foo->zorch in Perl? If it looks like duck typing and quacks like duck typing... ;)

Indeed, I believe we could use Perl's OO support and operator overloading to do exactly the same things as Ruby does, right down to accessing arrays and hashes with the same kinds of bracket. The reason we don't is twofold:

Replies are listed 'Best First'.
Re^3: Ruby Before Perl? Nah.
by Fletch (Bishop) on Jun 07, 2008 at 15:48 UTC

    Good points.

    The wikipedia article I referenced says "Perl's runtime method call mechanism naturally supports duck typing.". The thing is I think people writing Perl don't tend to think "the duck typing way" (if one might posit such a thing) to the extreme that Ruby encourages it. Not to mention that if you really want to in Ruby you can individually override / extend a single instance at runtime to implement an interface if need be (of course with Moose and friends you can do similar in Perl, so . . . ).

    And yes, there's overhead to the smalltalkesque everything's-an-object everything's-done-sending-messages model. Ruby's still got speed issues, but it's still got lots of elegant points. I'll often whip first passes of CSV munging together using Ruport because Ruport::Data::Table allows some really succinct code; if speed's an issue then it's time to drop back to Text::CSV_XS or Tie::Handle::CSV.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      The thing is I think people writing Perl don't tend to think "the duck typing way" (if one might posit such a thing) to the extreme that Ruby encourages it.

      I find it more likely that the Perl community doesn't fall all over itself to drool all over itself and slap new silly names on decades-old techniques blatantly and obviously ripped from other languages as do some parts of the Ruby community.