Alternatives To Inheritance

This is repost of a use.perl entry I made. You can clearly see the "before" and "after". Which do you prefer?


I'm planning to write a long article about alternatives to inheritance. Part of the issues with multiple inheritance in Perl programs seems to stem, in part, because there doesn't seem to be enough written about this from the Perl perspective

There's also not enough perspective from a "large-scale" standpoint. I still recall one person defending "mixins" because in years of programming, he's only been bitten by the mixin ordering problem once. However, when you start working on large scale, mission-critical applications with teams of programmers being rotated on and off the project, issues with multiple inheritance, silently overriding methods, mixin ordering and other issues are much harder to notice, much less track down. And even comprehensive test suites can miss that subtle bug which depends on a very unusual combination of factors. I speak from very painful experience here.

Test Test Test

Always test stuff. Testing is good.

A New Conference Season

The 2009 conference season hasn't ended yet and already I am booking flights for next year's conferences. It looks like I will be attending both Perl Oasis and Frozen Perl at the start of next year. I won't be travelling back to Japan between the conferences so I should also get some time to meet up with the Perl Mongers in Pittsburgh and New York.

The games afoot...

There is so much happening in the world of Perl at the moment...

  • New blogs (this was posted to https://blogs.perl.org/!)
  • New web designs (more on this another time)
  • New approaches (Moose, Catalyst, DBIx::Class etc etc etc)
  • New initiatives (Iron Man, TPF marketing etc etc)

I haven't historically been a blogger, but I think some of the projects I do at work (http://www.foxtons.co.uk/) as well as home might be of interest, so I'll try and do the occasional wright up here.

Test::Aggregate::Nested

Currently I'm trying to convert our work test suite over to Test::Aggregate::Nested. This is an alternative to Test::Aggregate which is much cleaner internally and relies on nested TAP, available in the latest versions of the Test::Simple distribution. Using it is pretty simple:

use Test::Aggregate::Nested;

my $tests = Test::Aggregate::Nested->new( {
    dirs => $aggregate_test_dir,
} );
$tests->run;

There are a few more features I need to hack in, but two nice advantages this provides are:

  1. The restriction on __END__ and __DATA__ tokens goes away.
  2. "Variable will not stay shared" warnings go away.

Regrettably, it turns out that I've introduced a regression in Test::Aggregate itself. Apparently, "no_plan" tests don't work correctly, but this may be the nasty hacks to the Perl internals which Test::Aggregate relies upon. Fortunately, the nested version minimizes those hacks quite a bit.

In praise of Try::Tiny

Try::Tiny is one of those tools that feels like it should always be in your toolbox. Handling exceptions in Perl is awkward; Java, JavaScript, Python, and Objective-C all provide native try syntax. Perl does, mostly, via eval {} blocks, but it's hinky. Errors coming out of the block aren't local by default, and it's almost a dozen lines of boilerplate to add it properly.

Enter Try::Tiny:

A Blog Post

Introducing blogs.perl.org . I'm so happy!

So close, so close ...

It appears that, at long last, we'll get a proper blogging platform! With syntax highlighting:

    sub add_to_list {
        my ( $self, $text ) = @_;
        return unless defined $text;
        $text = $self->interpolate($text);

        # This horror of horrors is because we want simple lists to be single
        # spaced, unless there are further details after the =item line, in which
        # case an extra newline is needed for pleasant formatting.
        my $break = '';
        if ( $self->list_data =~ /\n.ITEM\n.*\n$/ && $text !~ /^.ITEM/ ) {
            $break = "\n";
        }
        $self->list_data( $self->list_data . "$break$text" );
    }

And we even have images! (Not that they're helping this post look any better.

And if you look down below, you even see tags :)

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.