Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: Re: Often Overlooked OO Programming Guidelines

by scrottie (Scribe)
on Dec 30, 2003 at 03:49 UTC ( #317621=note: print w/replies, xml ) Need Help??

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

Hi again Ovid,

I've gone on personal missions to "fix" Perl's hackish OO. Object::Lexical is one attempt - instance data is held in lexicals and accessors/mutators are closures, created with Sub::Lexical. To quote the POD:

<code> use Object::Lexical; use Sub::Lexical; sub new { my $counter; our $this; my sub inc { $counter++; } my sub dec { $counter--; } my sub inc3x { $this->inc() for(1..3); } instance(); }

This skirts a few issues, which are issues unique to Perl:

  • Different syntax for instance data than other variables (my, local) makes refactoring code hard - every "$foo" must be changed to "$self->{foo}" manually.
  • No help from "use strict" and "use warnings" about only using a name once. None of the protection of requiring that a variable be declared first. In short, hash entries don't get all of the diagnostic helpfullness perl gives lexicals.
  • CPU overhead for hash lookups, memory overhead for storing hashes.

    Each object is given its own stash (namespace) which inherits from the namespace of the current package. The stash is populated with closures. Viola! Thanks to Juerd, by the way, who suggested creating things and stuffing them into stashes instead of sticking an AUTOLOAD to proxy to methods stored in hashes.

    Then there is typesafety: with its massive userbase of 0 users. This cultural divide miffs me - no Java user would ever consider a language that didn't have typesafety, and no Perl programmer would ever willingly use typesafety. Actually, I know (or know of atleast) a lot of people that lost their Perl jobs and had to get Java jobs, and now would never go back to Perl because of things like the lack of typesafety and other OO hackishness in Perl, which just goes to show, people don't know what's good for them.

    • Comment on Re: Re: Re: Often Overlooked OO Programming Guidelines
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (9)
    As of 2019-09-19 10:46 GMT
    Find Nodes?
      Voting Booth?
      The room is dark, and your next move is ...

      Results (242 votes). Check out past polls.