Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday August 05, 2004
02:13 PM

Is this code too strange?

[ #20255 ]

I thought about writing up something for Perlmonks demonstrating how test driven development (TDD) works with Test::More. The intent would be to write a short, but useful OO module that gives them a good sense of TDD. Then I realized I have an unusual enough coding style that I could possibly confuse more of the monks than help them. In glancing at this snippet, does it make sense (using private methods and named anonymous subs) or would it be too distracting from what I was trying to do?

my $_croak = sub {
    local *__ANON__ = '__ANON__croak';
    my ($proto, $message) = @_;
    require Carp;
    Carp::croak($message);
};

my $_validate_code_slot = sub {
    local *__ANON__ = '__ANON__validate_code_slot';
    my ($self, $code_slot) = @_;
    no strict 'refs';
    unless (defined *{$code_slot}{CODE}) {
        $self->$_croak("Cannot replace non-existent sub ($code_slot)");
    }
    return $self;
};

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If you lead off with those fragements, I suspect you'd lose a lot of folks who you could otherwise help. I had a hard time answering the "how, exactlyl, does this help me?" question.
  • The code is definitely too strange.

    Once you've read the perlmonks post it makes sense, but overall I think that the __ANON__ trick will obscure your main point. It might be better to keep the tutorial focused on showing how you write just enough code to pass the tests (which you are not quite doing when you use tricks like this BTW).

    --
    mirod
  • I'd just use the normal _leading_underscore convention that more people will be familiar with for a tutorial on TDD. You'll just have to spend time explaining the method, which will distract from your main point.

    (we must be on the same ley-line since I'm writing a little tutorial myself on TDD - not aimed at perlmonks tho :-)