in reply to Re: Do you consider these different or the same?
in thread Do you consider these different or the same?

I might reuse the same date object multiple times in the expected values even though the result values have multiple different occurrences of the same date value. I don't want that to be a problem.

Then you dont want a deep comparison, you want a shallow comparison. In fact you want the proposed 'looks_like()' method.

Finally in relation to is_deeply, it considers

$a=[]; is_deeply($a, "$a");
to be a pass.

Actually it doesn't. At least not in version 0.60

I and others know exactly what it's doing. Sometimes I use it, mostly I don't but changing its behaviour at this stage risks breaking tests and

My position is that we can eliminate the confusion by making is_deeply() do a proper deep structural comparison and provide a different routine (that would conveniently share its implementation with is_deeply).

Long term I believe this would clear up a LOT of misunderstanding about references that I see even experienced Perl programmers making. Misunderstanding such as is_deeply() considering $ar1 and $ar2 to be the same, which is just totally wrong.

my ($x,$y,$ar1); $x=\$y; $y=\$x; $ar1=[$x,$y]; my $ar2; $ar2->[0]=\$ar2->[1]; $ar2->[1]=\$ar2->[0]; is_deeply($ar1,$ar2); #this is wrong, wrong, wrong.

If is_deeply()'s behaviour doesn't change then it should have very large warnings on it that it doesnt do what it claims to do (that is checking if the objects are deep copies of each other.)

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

Replies are listed 'Best First'.
Re^3: Do you consider these different or the same?
by fergal (Chaplain) on Jul 01, 2005 at 14:01 UTC
    Then you dont want a deep comparison, you want a shallow comparison. In fact you want the proposed 'looks_like()' method.

    Not if my date looks like {day => 5, month => 11, year => 2005} because I need to look inside again. You might argue that the date shouldn't look like that but I just chose date as an example of where you have what is really a value which who's identity is irrelevant. The only reason it even has an identity is because Perl (and many other languages) do not allow you to represent structured values except by using what you might call "anonymous variables". Haskell, relational databases and probably lots of other pure functional languages on the other hand do not force this although they do allow it if you explicitly request it.

    Actually it doesn't. At least not in version 0.60

    It didn't do that in ver 0.39 (or thereabouts) either but that was reverted because it also fixed (I considered it fixed anyway) the overloaded reference behaviour. Version 0.60 might undo that but it also removes comparison of subrefs and seems to be completely broken for overloaded values, so I wouldn't be too sure that that will stay that way for very long.

    Assuming the docs are correct though is_deeply will still never look inside an overloaded object which to my mind is a far bigger sin against deepness than this problem, also not checking blessedness means that 2 deeply equal values will not necessarily react in the same way to method calls (in fact one of them may not even be an object).

    I've spent plenty of time arguing about the right thing for is_deeply to do but I stopped when I was convinced that is_deeply is not going anywhere new and that the author was not interested in trying to make it go anywhere new. It seems that its author has now changed his mind somewhat (with the sub refs thing) but I actually think he was right in the first place. It does what it does and it's been doing that for years now. Changing it's behaviour now makes no sense to me.

Re^3: Do you consider these different or the same?
by hv (Prior) on Jul 01, 2005 at 14:39 UTC

    My position is that we can eliminate the confusion by making is_deeply() do a proper deep structural comparison and provide a different routine (that would conveniently share its implementation with is_deeply).

    Then I guess we need:

    is_deeply() is_truly() is_madly()

    Hugo

      Heh. Except that is_madly() was accidentally named is_deeply() in the first place :-)

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