Perl

Easy Data::Printer in the perl debugger

I find myself often wanting the magic of Data::Printer when I’m debugging. Sometimes ‘x’ just doesn’t cut the mustard.

I’ve finally got bored of typing:

use Data::Printer alias => dp; 

in the debugger, and have taken some time to make it available automatically.

If you want to try it, add the following to $HOME/.perldb:

$DB::alias{dp} = 's/dp/DB::dp/';
sub DB::dp {
    eval { 
        require Data::Printer; 
        Data::Printer->import(colored=>1,use_prototypes=>0);
    }; 
    if ($@=~/Can't locate/) { 
        print 'Data::Printer is not installed';
        return;
    };
    print Data::Printer::p(@_);
}

You can test it works with the following:

perl -d -e '$DB::single=1; $a'
main::(-e:1):   $DB::single=1; $a
auto(-1)  DB<1> v
1==>     $DB::single=1; $a
  DB<1> dp { foo => bar }
{ 
    foo   "bar"
} 
  DB<2>

(Yes, you can use ‘-e 1’, but I have NonStop=1 in my parse_options() setting.)

[This entry was originally posted on my perl blog]

Testing

IRB, and when automation is easier than testing it manually

I spend a lot of time thinking about test automation.  We all know that, when it’s done right, it can save everyone time, increase test coverage, and eliminate a lot of tedious, repetitive grunt work.  The trouble is, when it’s done wrong, it becomes just as much of a millstone as the manual testing it replaces.  Witness:

  • The massive maintenance burden of keeping automated tests working when the products they are hard-coded to look for suddenly disappear from the site under test because they’re sold out.
  • The pain of debugging a test that’s given you an incomprehensible stack trace instead of a sensible error message.
  • The constant fine-tuning of automated tests to cope with slight changes to the user interface that prevent them from “seeing” the objects they are looking for.

…and so on.  I’m sure you can think of some more examples.  So, to sum up, if you’re going for test automation in a big way, you’ve got to plan carefully.  And you have to employ the same kind of programming best-practices as the developers do.  And, of course, you must be prepared to spend significant time on maintenance.  This is daunting, and, if you’re just dabbling in automation rather than being a full-time Test Automator, you probably aren’t prepared to make that kind of commitment for fear that it won’t deliver enough value to justify the time invested.  Game over.

Continue reading

Perl

Information Representation for Storage and Communication

There are many different data representations of a single piece of information – and many ways of interpreting data as information. In this blog entry, we show that, when designing systems, we have to distinguish information from its data representation in order to ensure the system matches its requirements of being authoritative or redundant, and to communicate this information using a fault tolerant representation.

Continue reading