Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I mean, you wouldn't want an uninitialised instance of your class floating around in the wild would you?

I aim for avoiding initialization most of the time. :) I/O heavy initialization for database backed objects is best saved until absolutely needed, and possibly saved until more than one object can be initialized at the same time. How many objects get constructed and never used? Make construction cheap and it doesn't matter. Save the memory and disk and CPU for the stuff you really need to use.

I have a rule now for my code...save all work until it's proven to be necessary. Don't initialize an object until a method is called on that object that requires it to be initialized. Extending that, use require-on-demand instead of 'use'. Don't even compile dependency modules until a caller wants an object of their type constructed. autouse packages when trying to get legacy code to perform (just refactor out those pesky imports and that indirect object syntax ... your maintainers don't really want either of those anyway). Use Abstract Factory with a require-on-demand design for new code. Design for modular run-time, not just modular maintain-time.

As long as objects can identify themselves uniquely and know whether they've been initialized or not, then the rest is no big deal. No need for fully initialized objects at all times.

--Dave


In reply to Re^2: Perl Object Initilization by armstd
in thread Perl Object Initilization by PyrexKidd

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 romping around the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found