Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: Often Overlooked OO Programming Guidelines

by ysth (Canon)
on Dec 30, 2003 at 06:02 UTC ( #317631=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Often Overlooked OO Programming Guidelines
in thread Often Overlooked OO Programming Guidelines

I disagree with the categorization of Perl's OO as a hack. I think it provides the minimal tools as part of the core language, and gives lots of room for addition, restriction, expansion, and factorization. This is evidenced by the wide variety of modules to change/enhance/replace/invert/etc. perl's core object model.

Whether it is good to have such a plethora of ways and means (that you have to go looking for) instead of a Single True Way To Do It, Blessed By The Core, is a separate discussion.

Update: Yes, Perl OO is constrained, and yes, it was grafted onto an existing language; I don't agree that the constraints are a consequence of the grafting. I think they are an intentional design decision (though from recent evidence, Larry wouldn't make the same decisions now).

Update: Seems we just disagree on what hack means. To me it means poor features based on external constraints (whether that be time, backward compatibility, grafting new features onto old code, or whatever). I think the limitations of Perl OO due to intentional design, not constraint, so I would call it minimalist rather than hacked.

Update: Perl has no useful subroutine prototypes even for non-methods, by the definition of prototypes in other popular languages. The purpose of Perl prototypes (user subs that work like builtins) doesn't apply to object methods.

Update: It's strange to see multiple inheritance cited as a reason to call Perl OO hackish. It's the one feature that isn't what I would call minimalist. It's also hard to see how you could accidentally use it. It's not my fault, Officer, the language made me use multiple inheritance. Click go the closing handcuffs.


Comment on Re: Re: Re: Often Overlooked OO Programming Guidelines
Re: Re: Re: Re: Often Overlooked OO Programming Guidelines
by Anonymous Monk on Dec 30, 2003 at 06:20 UTC
    I disagree with the categorization of Perl's OO as a hack.

    I'd classify Perl's OO as a hack: But that doesn't mean it isn't a useful, flexible, and powerful hack. But it *is* hacked / grafted on to an existing language, and the imposed constraints shine through the finished product.

Re^4: Often Overlooked OO Programming Guidelines
by hardburn (Abbot) on Dec 30, 2003 at 14:54 UTC

    Nah, it's a hack. Useful, but still a hack. Why?

    • Before even using objects (in the bless sense), a Perl programmer already has to understand references, packages, and complex datastructures. Java programmers create their first object when they write a "Hello, World!"
    • Lack of a good way of doing protected methods/attributes (many people think that doing private data can't be done, but it's do-able using lexicals declared at the top of the package)
    • No subroutine prototypes (well, no useful subroutine prototypes, especially in terms of objects)
    • No compile-time checking of method lookups, which consequently makes it:
      • Slow
      • Unable to inline constant methods
      • Impossible for use strict 'subs'; to help you
    • Generally makes it easy to do objects wrong

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: Re: Re: Re: Often Overlooked OO Programming Guidelines
by scrottie (Scribe) on Dec 31, 2003 at 07:21 UTC
    Hi ysth,

    "Hackish" is kind of vague, perhaps intentionally. I don't think anyone is saying perl's OO is bad, just quick and dirty. The implications of what it is are more interesting than what it is. Implications:

  • Not default. Programs aren't forced to use it. Good, in my book.
  • Not helpful.
  • Doesn't encourage good style.

    Negitives, point by point:

    Not Helpful:: That is, completely unhelpful in diagnostics and debugging compared with virtually any other OO implementation. Privacy levels, prototypes/typechecking, and so on exist to help a programmer who can't keep a large project in his head (or a team of programmers who can't). If a method doesn't exist I'm trying to call, I want to know about it at compile time, not a month down the road when a client clicks on things in the wrong order and some corner case runs.

    Doesn't encourage good style:: Java is adding multiple inheritance grudgingly, and a lot of people say they shouldn't. It has willfully not so far. So, Java makes good style easy and bad style possible. Perl makes bad style easy and good style possible. Privacy, finalization, data hiding, strict typechecking (yes, you heard me) and so on are all possible in Perl, but they aren't easy. They require additional syntax and sometimes don't mesh well with other language features. On the other hand, breaking encapsulation, multiple inheritance, and other things of questionable style are all easy in Perl. This doesn't matter if you know your way around, but a novice programmer assumes that is easy is what they are supposed to be doing. If the langauge encourages you to multiple inherit and encourages you to access data in a class as if it were a hash, then it must be the best way. People don't read documentation until and unless all other things fail. This is a well known principle =)

    So, when I say Perl's OO is hackish, what I personally mean is it is something that kind of happened through tinkering and building (hacking), not something designed, specified, tested on focus groups, with second opinions from industry experts. But that doesn't mean that we can't continue to hack on it in future versions (eg, 6) and do RFC processes to form a coherent design, learn from feedback, visiting Java programmers, and so on. Hackish isn't fundamentally bad. It fits with "release early, release often". We just need to hack on it some more so it is less hackish =)

    -scott
      If a method doesn't exist I'm trying to call, I want to know about it at compile time

      You aren't going to get missing-method detection at compile time in a dynamic language, so that won't qualify in my book as part of Perl's OO 'hackishness' (I guess it can in your book, but then you'd also need to find Ruby and Smalltalk's OO hackish as well).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-04-20 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls