in reply to Re^6: The trap of reference numification
in thread The trap of reference numification

The correct fix is to have references throw an error when numified or stringified. Period, end of story. If you want to stringify a reference, use ref(). If you want to numify a reference, use ref_addr(). If you want something unique, use some combination of the two.

Solve the problem. Don't throw a random bandaid on it.


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?
  • Comment on Re^7: The trap of reference numification

Replies are listed 'Best First'.
Re^8: The trap of reference numification
by eric256 (Parson) on Nov 12, 2005 at 02:30 UTC

    He proposed that. You then gave situations where you don't do what you just suggested to to. I think it might help if you stated your view a little clearer, or at least mentioned that you changed views or the poor OP is going to go crazy trying to talk to you.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
      Throwing an error is different from throwing a warning. I'm proposing that numification or stringification of a reference should be considered a runtime error, should die(), set $@ and all that jazz. Unfortunately, the meme of my $x = Foo->new; print "$x\n"; is so ingrained that it's an impossible solution to propose.

      Throwing a warning is just plain old annoying. Now, making it an optional warning wouldn't be a bad idea.


      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?
        All warnings are optional, in the sense that you can turn them off with a fair degree of specificity.

        I'd be fine with there being no implicit numification, but I think that causing interpolation of some scalars into strings to kill your program is a Bad Idea. Correspondingly, I think that stringification is much less of a stumbling block, so maybe you could get half your wish.


        Caution: Contents may have been coded under pressure.
Re^8: The trap of reference numification
by demerphq (Chancellor) on Nov 12, 2005 at 11:24 UTC

    I dont think this is the correct fix. It totally overlooks overloading and it ignores that people often want to stringify or numify refs legitimately. And refaddr() on older perls uses stringification to do its job.

    ---
    $world=~s/war/peace/g

Re^8: The trap of reference numification
by Perl Mouse (Chaplain) on Nov 14, 2005 at 10:56 UTC
    Solve the problem. Don't throw a random bandaid on it.
    As far as I see it, the problem is a programmer using an ambiguous variable name, $row, of which he can't remember whether that's a count, or a reference to an array.

    The bandaid is introducing a warning in Perl.

    I'd say the programmer should fix his naming scheme. Doesn't Perl Best Practises have a say on naming variables as well?

    Perl --((8:>*