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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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: http://search.cpan.org/~swalters/typesafety-0.04/ 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.

    -scott

    In reply to Re: Re: Re: Often Overlooked OO Programming Guidelines by scrottie
    in thread Often Overlooked OO Programming Guidelines by Ovid

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others imbibing at the Monastery: (6)
    As of 2024-04-16 07:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found