Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
[Discipulus]: Ah! if so you must play with him not with us ;=)
[vrk]: Hope he gets better soon.
[Discipulus]: hdb sorry i profit; is known that a prime number is never a figurate one nor the sumattion of two adjacent figurates of the same order? like 3th triangular+3th tetrahedric
[Discipulus]: if known where i can read about the matter?
[choroba]: he's not really sick, we just got nobody to look after him today
[Discipulus]: create an account for him; we are funny baby sitters ;=) come here child, want to listen the typeglob tale?
[vrk]: choroba Oh, that's good.
[vrk]: Discipulus I don't know much about prime numbers, but wouldn't that kind of an answer be in a graduate-level number theory book?
[Discipulus]: my 8 yo daughter has two weeks of sleep disturbs.. we are gonna be crazy..

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-04-27 07:57 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (501 votes). Check out past polls.