Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

When I read this post, I zeroed in on:   So, “I need to be sure that when I get rid of an object of this class, the cleanup happens immediately.”   And my strong recommendation is:   “find a way not to have to care about that.”

Reading further, I see that the core problem is that, to this application, “keys” are actually not “temporally unique” at all.   As the OP says, “the same key may come back fairly soon.”   The application obviously has no control over this:   the key, in other words, whatever it may be, is originating from the business.

When something like this happens ... and it does happen a lot in the real world ... I normally solve the problem by treating these “external” keys as surrogate keys.   I do not use them to “uniquely” identify the records that the application must store, knowing that (for my technical purposes) they might not be unique.   Instead, I generate truly-unique, internal-only keys for the records that I need to store, and I map the business-provided keys to them.

Very importantly:   it may well be that there is not a “one-to-one relationship” between the business-provided keys and my internal, known to be really-unique, mappings.   (Should be ... “always” swear-to god-and hope-to die should be ... but there ain’t.)   And so, ever so much more importantly, in spite of this “inconvenient truth,” my application nevertheless did not fall-down and burn in some kind of “I never thought this could happen to me” heap.   The business might have screwed-up, but I’m still standin’.   “Priceless.”

Business-provided identifiers do all sorts of weird things in real life, because human beings are responsible for every bit of it.   Well, humans can deal with that sort of thing; computers can’t.   So, you have to find a way that the computer can, because in any argument between the computer and a human, the computer is the one that has to budge.

Even when designing the internal storage architecture, I try to avoid having many references-to the same “storage object.”   Instead, I assign each object a (application-generated, not disclosed to anyone) random truly-unique key, and refer to it elsewhere using that key.   Yes, that involves an additional hash-lookup.

If the business’s way of handling “an identifier” is posing problems to your application ... don’t try to fancy-pants program around it:   instead, map what you are given to something else (which you give to no one) which does meet the computer’s requirements.   Whatever you do, stay on your feet.


In reply to Re: Timing of garbage collection by sundialsvc4
in thread Timing of garbage collection by dd-b

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 about the Monastery: (5)
As of 2024-04-18 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found