Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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.

Replies are listed 'Best First'.
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.

      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.


      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?
        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.
        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://507830]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-03-25 04:51 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (311 votes). Check out past polls.