demerphq writes:

> On 7/1/05, Michael G Schwern <[EMAIL PROTECTED]> wrote:
> 
> > ... I'm of the opinion that is_deeply() is currently doing the right
> > thing ... Largely it comes down to the Principle of Least Surprise.
> 
> I cant agree with this analysis. If you go down this route surprise
> abounds.
> 
> is_deeply($x,$y);  #ok
> 
> $x->[0]{a}=1;
> $y->[0]{a}=1;
> 
> is_deeply($x,$y);  #Surprise!

For those of us not following along too closely (and without the right
stuff installed to test the above line right now), it isn't clear what
the answer to the above is -- since it's the thing being disputed and
there are apparently arguments on each side, either result is of course
possible -- that you find surprising.

$x and $y look to contain the same data when looked at deeply to be, so
I'd expect them to compare the same; I'd be surprised if they didn't,
which I think means I disagree with you.

> Thats a MUCH bigger surprise IMO. And a fatal one for anybody really
> relying on is_deeply.

I'd say exactly the same about it comparing them differently.

> > In fact, I would even argue that this violates some of the black
> > boxness of the test.  In much the same way that we don't check to
> > see if a given piece of data is blessed, tied or overloaded, we
> > wouldn't care if we have a repeating reference or two different
> > references to equivalent data.
> 
> But they COMPLETELY change the datastructure. Utterly and totally.

Not necessarily.  It depends on what you're using the data for.

> The question you have to ask yourself is why should a reference be
> treated different from any other value? It is a VALUE.

Except it isn't.  Or at least, not all the time: it depends how you wish
to look at it.  If you just consider a reference to be a value
(effectively a pointer, a memory address) then you aren't examining a
data structure _deeply_; you're just doing a _shallow_ comparision of it
as a reference.

> IE: why should [tweaked as per later mail]
> 
> $x=1;$y=1;$z=2;
> 
> $a1=[$x,$x];
> $a2=[$y,$z];
> 
> $a1 and $a2 are different but

Clearly, because you've assigned different values into $x and $z.  If
you'd assigned the same values into each of them then they should
compare as the same:

  $x=1;$y=1;$z=1;

> $x={};$y={};$z={};
> 
> $a3=[$x,$x];
> $a4=[$y,$z];
> 
> $a3 and $a4 are not?

In this case you've assigned the same value -- an empty hash ref -- to
each of $x and $z, so the data structures in each case are the same.

> Isn't the situation identical?

No.  Just look at the source code:

  $x=1;$y=1;$z=2;
  $x={};$y={};$z={};

A system in which the 1st of those lines puts something different in the
variables but in which the 2nd puts the same in each variable seems
entirely plausible to me.

> ... the refs turn into their addresses and you will consider them
> different? This just doesnt make sense.

Yes it does, cos once you're looking at the value of refs that's become
a shallow copy -- you're no longer bothered by what's inside them.
Going back to your first example:

> $x=1;$y=1;$z=2;
> $a1=[$x,$x];
> $a2=[$y,$z];

$a1 and $a2 are different, and you seem happy with that.  Suppose it
were instead:

  $a1=[1, 1];
  $a2=[1, 1];

Would you be happy for $a1 and $a2 now to compare the same?  If not then
obviously you never need to use is_deeply cos you could just use ==
instead (and treat the array-refs as values).  If you are happy for them
to compare the same, despite being different anon array-refs in memory,
then why aren't you happy for the same rule to apply nested within those
array-refs?

To me 'deeply' implies recursing as deep as the data structure goes, not
that there's a special rule for the top-level that's treated differently
from the others.

> is_deeply should be reliable and do what its name says.

I think everybody's in agreement about that!  There's just the matter of
agreeing what its name does say ...

> The fact is it wouldnt be too difficult to support both [behaviours]
> off of the same code base.

Then we're still in the position of arguing which should be the default
behaviour ...

Smylers
-- 
May God bless us with enough foolishness to believe that we can make a
difference in this world, so that we can do what others claim cannot be done.

Reply via email to