in reply to Perl fan being tempted with Python

What's not native about Perl's OO?

It supports object creation natively:
bless({}, $class);

It supports inheritance natively:
$child->parent_method()

It supports method calling natively:
class->method();       # Static
$obj->method();        # Virtual
$obj->class::method(); # Non-virtual, Inherits
class::method($obj);   # Non-virtual, Doesn't inherit

As a derict result of the above, encapsulation and polymorphism is natively supported. Perl doesn't support security divisions, but that's just a luxury (or a curse).

Replies are listed 'Best First'.
Re^2: Perl fan being tempted with Python
by Fletch (Chancellor) on Jun 16, 2005 at 18:24 UTC
    #!/usr/local/bin/ruby class Numeric def secs_to_minutes self / 60 end def minutes_to_hours self / 60 end end puts 86400.secs_to_minutes.minutes_to_hours

    Usually what's meant by "pure OO" (which is what I presume the OP meant by "native") is that everything is an object. In Perl (and Java, and C++) there are underlying primitive data types which aren't first class objects in their own right (granted Ruby cheats with small integers under the hood :).

    Update: Tidied up wording

    --
    We're looking for people in ATL

Re^2: Perl fan being tempted with Python
by Anonymous Monk on Jun 17, 2005 at 11:29 UTC
    What's not native about Perl's OO?
    Answer:
    bless({}, $class);

    The fact that you have to build your own objects reusing other bricks, and some spit named bless gives a strong impression that OO is bolted on to Perl, and not native. A Larry has said, OOP was an experiment in how minimalist one could design OO.

    The syntactical sugar for calling methods doesn't make objects "native". There's no object type in Perl, I can't subclass integers or arrays (unless you call the 'tie' mechanism 'subclassing').

    I'd call OO in Perl workable. But not native.

      The fact that you have to build your own objects reusing other bricks, and some spit named bless gives a strong impression that OO is bolted on to Perl, and not native.

      Impression? maybe. I'm not sure how that matters. Besides, bless({...}, $class); looks just like new class(...) (C++'s syntax) to me.

      A Larry has said, OOP was an experiment in how minimalist one could design OO.

      True, but this has no bearing on whether objects are native or not.

      The syntactical sugar for calling methods doesn't make objects "native".

      That's an odd statement. Something which is part of the language's syntax is sugar, and not built-in? Acknowkleding it's part of the syntax makes it builtin!

      There's no object type in Perl

      Then how come ref says it's an object?

      I can't subclass integers or arrays (unless you call the 'tie' mechanism 'subclassing').

      You can't do that in C++ or Java either.

        You can't do that in C++ or Java either.

        Exactly, which is why they're not considered "pure OO". I think it comes down to the OP's somewhat ambiguous use of the term "native". It's not clear whether they meant native-as-in-part-of-the-language or naitive-as-in-pure-OO.

        --
        We're looking for people in ATL