Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Should bless be automatically redefined or explicitly as shown in the example above? It would almost always be imported, but making it explicit highlights the fact that bless is doing something unusual. Without the import, it could be called as InsideOut::Helper::bless( $self, $class ) of course.

I'd suggest that you call it "register" instead, as you proposed later. And force the user to export only the functions they need, explicitly. That way, it's easier to maintain: if you export fifteen functions, I need to check the codebase to see if any of those fifteen functions are still in use before I can remove the module from the codebase. If you only export what you actually use, then maintaining the code and removing unused modules becomes much easier. I'm lazy; I'd rather write down what I know when I know it (such as what functions I'm using from a given module), rather than waste time trying to reconstruct what I've forgotten.

Is redefining bless a bad idea? Should I just import a separate function like register instead to register the object after it's blessed using the built-in bless? E.g. register( bless $self, $class )

I don't see the need to redefine "bless"; just tell people to use "register" instead of "bless". You call the core "bless" function, so you should be able to use register exactly as you do "bless". In general, I find redefining builtin functions is always more confusing than not doing so. If I read "register", I know immediately that I don't know what's going on, and that I need to learn more. If I read "bless", I might be fooled into the wrong assumptions.

Just my $0.02
--
Ytrew


In reply to Re: Overriding bless for inside-out object safety by Anonymous Monk
in thread Overriding bless for inside-out object safety by xdg

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 drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found