--- Piers Cawley <[EMAIL PROTECTED]> wrote:
> I've always thought of C<is_deeply> as being about the 'shape' of a
> data
> structure. When you think of things in this way, then it seems
> obvious that given
> 
>     $a = [], $b = [], $c = []
> 
> then [$a, $a] and [$b, $c] have substantially different shapes.

That's not obvious to me.  When I look at that, I ultimately see this
*shape* for each: "[[],[]]".  In other words, I'm just looking for what
data is arranged in what type of data structure.  I'm not really
considering how that structure might mutate given that someone comes
along later and changes one of the values.  I'd write a test for that. 


Heck, if we're going to consider that, why would this pass?

 my $a = [1,2,3];
 my $b = [1,2,3];
 is_deeply $a, $b, '...';
 is_deeply $a, $a, '...';

That should pass nicely, but start shoving those array refs in other
array refs and things fail?  I don't see why.

The argument seems to be that when we have [$a, $a] and [$b, $c],
changing the value of $a in the first changes the value of the other $a
and therefore the two array refs are not *functionally* equivalent.  I
want to know if the *data* are the same for a given test (which I like
to think of as a snapshot in time).  Whether or not the *behaviors* are
the same is the reason I write more than one test.  (Yes, I know that
some might consider wether or not the references refer to the same area
of memory as important.  If so, don't use is_deeply.  Perhaps we should
have another test function?)

So, just for the sake of argument, imagine I write a class where I
periodically returns array refs to the user.  I do this by building
them every time they're called.  Later, I realize that my methods are
deterministic so I start caching results and returning them instead of
rebuilding the array each time.  I'm expecting my test suite to still
continue working but under this proposed idea, it could be a nightmare
for me to debug.  Heck, when I print out the arrays with Data::Dumper,
I'll see the same values and be mystified why they're not equivalent.

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

Reply via email to