in reply to debugging - straw poll ...
I used to do exactly the same as come of the comments here suggested: print statements, data dumper, and so on
Now I'm going 'agile' by including unit tests from the beginning of my coding, even if inheriting code from others.
In fact, I write tests first, then start coding to make them work. It's a different approach. My 'debugging' time decreased in the end because I was able to find many more mistakes early on.
Give it a try, google on unit testing. There's even a book on Extreme Perl and Test-Driver Design
An example: a simple accumulator. I start with writing Add.t first (the code at the end) and fill up Add.pm (first code on top) to make Add.t run without failures...
package Add; use strict; use warnings; sub new { my $class = shift; my $self = { ACC => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless ($closure,$class); return $closure; } sub acc { &{ $_[0] }("ACC", @_[1 .. $#_]) } sub add { acc( $_[0],acc( $_[0] )+@_[1 .. $#_] ); } 1;
use strict; use warnings; use Test::More tests => 7; BEGIN { use_ok('Add'); } ok(my $a = Add->new(),"creation of accumulator"); ok($a->acc(3),"accumulator set to 3"); isnt($a->acc,0,"check if accumulator isn't zero"); is($a->acc,3,"check accumulator equals 3"); ok($a->add(3),"add 3 to accumulator"); is($a->acc,6,"check if add equals 6");
|
|---|