Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Re: Re: Functional Inside Out Closure Objects

by stvn (Monsignor)
on May 20, 2004 at 17:52 UTC ( [id://355035]=note: print w/replies, xml ) Need Help??

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

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.


Replies are listed 'Best First'.
Re: Re: Re: Re: Functional Inside Out Closure Objects
by jdporter (Paladin) on May 20, 2004 at 18:44 UTC
    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).


        "You keep using that word ("syntax"). I do not think it means what you think it means."

        There's no reason you can't think of use base as a keyword with a space in it.

        Note, I'm not necessarily disagreeing with your complaint about the mechanics of Perl's OO... although I happen to be quite fond of it.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-05-25 07:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found