Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: The trap of reference numification

by itub (Priest)
on Nov 11, 2005 at 19:12 UTC ( #507830=note: print w/ replies, xml ) Need Help??

in reply to The trap of reference numification

I don't know if it's that rare; I've seen it used quite a bit to generate an object ID of some sort (stringification is also used for that). If you add that as a warning, many currently warning-free programs would start spewing lots of warnings, which might be annoying... But I agree that in principle such a warning would be useful, and I imagine the same drawbacks apply whenever a new warning is added.

Comment on Re: The trap of reference numification
Re^2: The trap of reference numification
by friedo (Prior) on Nov 11, 2005 at 19:21 UTC
    In my experience object IDs almost always use the stringified reference as a hash key (the usual way for inside-out objects.) Or Scalar::Util::refaddr is used (as in Class::Std and PBP.)

    refaddr returns the numified reference, but Scalar::Util already turns warnings off when munging that. (And SU does it in a rather bizarre way with a regex and hex instead of using direct numification for reasons that remain mysterious to me.)

    I don't think there are many common uses of numified references outside those two contexts.

    Update: Actually it looks like the issue with refaddr is fixed in recent versions. It uses int now.

      Comparisons between objects. Depending on my mood, I'll use eq or == interchangably. Before we go ahead and do this, there needs to be considerable discussion. This will end up being a bigger change than expected.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        I don't think anyone was proposing that it be done without major discussion. I assume that the usual erudite discourse and flamewars to light up the night sky will take place on p5p. Personally, I think the change would be worth the effort.
        Comparisons are one thing, but I seriously doubt you do math ops on them (like in this case, using the modulus operator). If the warning recognized that situation, I suspect it would be pretty close to The Right Thing.

        Caution: Contents may have been coded under pressure.

      And SU does it in a rather bizarre way with a regex and hex instead of using direct numification for reasons that remain mysterious to me.

      The answer to that is simple: overloading. Up until later perls (and even in them im not sure) there was no way to bypass overloaded nummification. Thus 0+$ref is inherently dangerous on a blessed ref. However there is and has always been a way to bypass overloaded stringification which conveniently contains the reference address in hex. Thus the only generally safe pureperl way to get the address of a ref is via this technique.

      Having said that SU doesn't use the pure perl code except on older perl builds on OS'es/Machines that dont have XS installed. The XS code it uses for refaddr() is much more efficient and bypasses all of these problems.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-01 07:59 GMT
Find Nodes?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?

    Results (810 votes), past polls