Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: Functional Inside Out Closure Objects

by sth (Priest)
on May 20, 2004 at 17:19 UTC ( #355023=note: print w/replies, xml ) Need Help??

in reply to Re: Functional Inside Out Closure Objects
in thread Functional Inside Out Closure Objects

Personally, I never really thought of OOPerl as hard, ugly yes,

Ugly? why?


  • Comment on Re: Re: Functional Inside Out Closure Objects

Replies are listed 'Best First'.
Re: Re: Re: Functional Inside Out Closure Objects
by stvn (Monsignor) on May 20, 2004 at 17:52 UTC

    To start with, perl's object system was a bolt-on to the existsing module system, which is both ugly (because it kind of exposes the soft underbelly of objects) and cool at the same time (you can do some crazy stuff with modules/typeglobs, and you can now do them with objects too :)

    How it handles inheritance is another.

    package Foo; @ISA = qw(Bar);
    This takes the idea of inheritance and converts it into a "magic" laden assignment statement. This exposes too much of the details of how perl manages inheritance, which IMO is ugly. Maybe I am a purist, but I think that declaring inheritance should be part of the class declaration, or at the very least have its own keyword.

    Constructors in perl are nothing special, which at first glance is cool, but it does lead to some ugly code when calling base class constructors in subclasses. I personally like the C# syntax for these things:

    class Bar { string name; public Bar (string name) { = name; } } class Foo : Bar { Hashtable attributes; public Foo (string name, Hashtable attributes) : base(name) { this.attributes = attributes; } }
    Also, the idea that an object is just a blessed reference IMO is another double edged sword. It makes encapsulation a big issue/problem. (Sure I know you can do Inside-Out objects and closures, etc etc etc, but all of them just add to the already touchy syntax.) Now I know the idea is that you shouldn't mess with the internals because you were not invited, and that it then becomes a social problem. But I would rather not have the social problem at all and have strong encapsulation.

    All this said, I love perl, so I have worked with/around all this stuff in my own way, but it doesn't change the underlying ugliness of it. And yes, some might call this elegance, and I will be the first to admit that there is a fair amount of elegance in how minimally invasive the adding of objects to perl was, but when you get deep into the thick of it, there is some real ugliness there no matter what.

      This takes the idea of inheritance and converts it into a "magic" laden assignment statement.
      Huh? use base was invented to address those concerns. Check it out.

        I am familiar with base, but the base pragma is an addition to the perl OO syntax not part if the actual syntax itself. Like I said, I would rather it be either a keyword like extends or it be part of the class declaration process (of which there really is none, its just a package declaration, and bless makes it a class).


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://355023]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-05-20 05:30 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (72 votes). Check out past polls.