Recently in Programming Category

I recently uploaded a new distro to CPAN recently called Type. The concepts are largely on Moose's built-in type system, but it's a standalone distribution.

Right now this is all very alpha, and the current release is not intended for use by anyone. I've released so people can take a look at critique the design. I've tried to remedy some of the problems that Moose's type system has. MooseX::Types fixes some of these problems but then introduces its own. Type addresses the problems of both.

My long-term goal is to replace Moose's built-in system with Type. This will probably mean rewriting Type to not use Moose itself. The current release uses Moose because it made it easy to prototype the system.

Here's the comparison with Moose and MooseX::Types from the Type distro's docs:

Type names are strings, but they're not global

Unlike Moose and MooseX::Types, type names are always local to the current package. There is no possibility of name collision between different modules, so you can safely use short types names for code.

Unlike MooseX::Types, types are strings, so there is no possibility of colliding with existing class or subroutine names.

No type auto-creation

Types are always retrieved using the t() subroutine. If you pass an unknown name to this subroutine it dies. This is different from Moose and MooseX::Types, which assume that unknown names are class names.

Exceptions are objects

The $type->validate_or_die() method throws a Type::Exception object on failure, not a string.

Anon types are explicit

With Moose and MooseX::Types, you use the same subroutine, subtype(), to declare both named and anonymous types. With Type, you use declare() for named types and anon() for anonymous types.

Class and object types are separate

Moose and MooseX::Types have class_type and duck_type. The former type requires an object, while the latter accepts a class name or object.

In Type, the distinction between accepting an object versus object or class is explicit. There are four declaration helpers, object_can_type, object_isa_type, any_can_type, and any_isa_type.

Overloading support is baked in

Perl's overloading is broken as hell, but ignoring it makes Moose's type system frustrating.

Types can either have a constraint or inline generator, not both

Moose and MooseX::Types types can be defined with a subroutine reference as the constraint, an inline generator subroutine, or both. This is purely for backwards compatibility, and it makes the internals more complicated than they need to be.

With Type, a constraint can have either a subroutine reference or an inline generator, not both.

Coercions can be inlined

I simply never got around to implementing this in Moose.

No crazy coercion features

Moose has some bizarre (and mostly) undocumented features relating to coercions and parameterizable types. This is a misfeature.

Your feedback is requested

The current distro has mostly complete docs, so it should give you a sense of what I'm aiming at.

I'd love to hear from the Perl community on this distribution. Do this seem like it'd help fix problems you've had with Moose types? Can you imagine using this distribution without using Moose? What's on your wishlist?

Rules of Optimization

| 2 Comments | No TrackBacks

For that coworker who won't stop "optimizing" his or her code, I give you my rules of optimization:

  1. Don't optimize
  2. Don't optimize, I'm serious
  3. Don't optimize without benchmarking first
  4. Don't benchmark without profiling first
  5. See rule #1

Edit: A co-worker suggested a step 4.5 of "Take a coffee break". I don't like coffee, but I like the spirit of the suggestion.

git-age-report

| 4 Comments | No TrackBacks

At work we have some git repos that were converted from CVS originally created back in 2002 or so. A lot of the things in these repos is cruft and could be deleted. I wrote a little git command to report the most recent commit date for each thing in the current directory.

#!/usr/bin/env perl

use strict;
use warnings;

use DateTime;

my %age;
for my $thing ( glob '*' ) {
    next if $thing =~ /^\.\.?$/;

    my $epoch = `git log -1 --format="%at" $thing`;
    chomp $epoch;

    $thing .= '/' if -d $thing;
    push @{ $age{$epoch} }, $thing;
}

for my $epoch ( reverse sort keys %age ) {
    my $dt = DateTime->from_epoch( epoch => $epoch );

    print $dt->date(), "\n";
    print "  - $_\n" for @{ $age{$epoch} };
    print "\n";
}

I wrote another article for LWN that has just come out from behind the paywall, Perl 5.16 and beyond. This covers changes in Perl 5.16 and future plans for Perl 5.

I wrote an article for LWN (Linux Weekly News) about the Perl 5 release process a couple weeks back. It was originally behind a paywall but it's now readable by anyone.

Another article I wrote will be published later today. I'll post a link here once it's out from behind the paywall.

Please consider subscribing to LWN if you like this sort of thing, of course.

I feel that Perl 5 activity has increased over the past few years, but is that an illusion? I brought this topic up on the #p5p IRC channel and Nicholas Clark said, "everyone assumes growth. If you look at the 'committers' graph on https://www.ohloh.net/p/perl/analyses/latest I don't think there's been any marked growth (or reduction) in the past 10 years. Just a lot of noise".

So is he right? I wanted to figure it out.

The Ohloh chart is very noisy. It shows the number of committers per month, which seems to swing back and forth rather dramatically. I used the Ohloh API to download the raw data and run it through a spreadsheet.

Instead of looking at each month, I looked at the average number of committers per year. I started with 2001, since before that year the data is even more wildly variable. Also, I know that the farther we go back in the commit history, the more guesses were made during the import to git.

Here's the graph I created in Gnumeric:

perl-commiters-per-year.png

It looks like there was a big dropoff in committers from 2001 to 2004, and we've seen an upwards trend since then. I'm not sure there's enough data to draw any strong conclusions. My gut feeling that activity was up in the past few years was correct, but we don't yet know whether that's a fluke.

We still haven't reached our historical highs, so I think Nick was right when you look at the overall history of Perl 5. Nevertheless, I'm hopeful that we're in the midst of a positive trend.

I'm going through the Netflix movie rating interface right now rating films & tv shows to try to improve my recommendations. Sometimes after you rate something it asks you how often you watch films of a certain category. Presumably the category the thing you just rated belonged to.

Some of the categories make sense, and some are completely insane. I can't figure out how they could possibly be useful in determining what I like. Some good examples ...

  • Parks and Recreation - NBC TV Shows

    I don't give a flying crap what network the show is on. I can think of several other categories it belongs to that seem more relevant (sitcom, documentary approach sitcom, etc.)

  • 28 Days Later - Viral Plague Movies

    Yes, I love those viral plague movies. But bacterial and fungal plague movies suck. Of course, what's really silly is that this is obviously a zombie movie, not a plague movie. The mechanism of zombiefication is really not all that relevant.

  • Evil Dead - Demon Movies

    Not horror, not comedy horror, not indie horror. Demon movies. Yes, because horror movies with non-demon monsters are so different.

  • Lust, Caution - WWII Movies

    Ok, yes, technically, this is a movie set during World War II. Of course, when people think of WWII movies they generally think of movies about American involvement in the war, or maybe at a stretch things that happened in Europe. This is a movie set in China, in Chinese, with Chinese actors. I suspect most people think of this as simply a foreign movie or a Chinese movie.

  • Religulous - Spiritual Documentaries

    Uh, WTF?

  • The Blair Witch Project - Wilderness Survival Movies

    Ok, yes, they're in the wilderness. And yes, they're trying to survive. But again, WTF?

It seems like in many cases, they've identified some incidental feature of the thing in question and decided it is somehow meaningful.

Anyway, I'd love to hear comments from people who understand recommendation systems better. Do these categories actually make sense?

The Perl 5.15.6 Epigraph

| 3 Comments | No TrackBacks

Today I had the privilege (or punishment?) of releasing Perl 5.15.6, the latest monthly dev release of Perl 5. Part of the Perl release tradition is to include an epigraph with each release. The epigraph is a quote of some sort that goes at the beginning of the release announcement.

I can't find the first epigraph but if I had to guess it must be a quote from Tolkien accompanying one of the releases Larry Wall did. The source code for Perl itself is liberally littered with Tolkien quotes.

One of the reasons I wanted to do a Perl release was to have an opportunity to choose my own epigraph (weird motivation, but true). I had a few criteria in mind.

First, I wanted to choose a writer I respected as a writer, something I'd want other people to read. Second, I wanted to pick a new author (not Tolkien ;). My first inclination was to find something in one of the Kushiel Trilogy books by Jacqueline Carey, who is one my favorite authors, and probably not that well known in the Perl community.

One of the main themes in these books is love as a motivation for sacrifice. I think that the people who work on Perl are at least in part motivated by love. We have love for the language and for the community. We could all spend our time on other things like making more money, sleeping, or watching more TV, but we hack on Perl instead.

Unfortunately, finding a quote isn't all that easy. It's been a few years since I read the books, and I couldn't remember any particular piece off hand. I tried using Amazon's "look inside" feature, but I just couldn't find anything. I started browsing my bookshelves looking for something else.

It finally came down to a quote from Matt Ruff's Set This House in Order and the one I chose, from A Wizard of Earthsea by Ursula K. LeGuin. The Ruff quote was great, but it specifically refers to being born at age 26, and Perl just turned 24 (on December 18, 2011), so I thought that might be a little confusing. Maybe I can volunteer to release 5.19.6 in December of 2013.

The quote I did choose is:

Ged had thought that as the prentice of a great mage he would enter at once into the mystery and mastery of power. He would understand the language of the beasts and the speech of the leaves of the forest, he thought, and sway the winds with his word, and learn to change himself into any shape he wished. Maybe he and his master would run together as stags, or fly to Re Albi over the mountain on the wings of eagles.

But it was not so at all. They wandered, first down into the Vale and then gradually south and westward around the mountain, given lodging in little villages or spending the night out in the wilderness, like poor journeyman-sorcerers, or tinkers, or beggars. They entered no mysterious domain. Nothing happened. The mage's oaken staff that Ged had watched at first with eager dread was nothing but a stout staff to walk with. Three days went by and four days went by and still Ogion had not spoken a single charm in Ged's hearing, and had not taught him a single name or rune or spell.

I think this quote works on several levels. First, it reflects the difficulty of hacking on the Perl core's C code. It's some serious magic, and you won't become a great mage all at once. Second, this same dynamic of slow learning applies to programming in general. It seems like great magic, and you wish you could master it all at once, but it takes quite some time before you've figured it out. This is actually one of the themes of all the Earthsea books, that mastery takes a long time, and that maybe you never really become a master. Instead, you just learn clearly how little you actually understand.

I feel like this with programming all the time. Even if I felt like I really "got it" I can always look back at my work a year later and see just how clearly I didn't "get it" at all.

Unfortunately, choosing Ursula K. LeGuin probably doesn't satisfy my desire to pick someone who might be new to people in the Perl community. Oh well, maybe next time!

I hope that in the future other Perl release managers will write blog entries similar to this one explaining the quotes they chose. I'm always curious what the quotes mean to the person doing the release, although occasionally they're quite straightforward. I added an entry to the Perl Release Manager's Guide asking folks to blog about their epigraph after the release.

Here's looking forward to Perl 5.15.7 (and it's accompanying blog entry).

VegGuide Needs a New Host

| No Comments | No TrackBacks

For many years, the VegGuide site has been hosted for free at Xmission, courtesy of Eric Waters. Eric has recently moved to a new position and is no longer at Xmission, so it's time for us to find a new host.

Update: The site is owned by my animal rights group, Compassionate Action for Animals, and we are a 501(c)(3) non profit organization.

If anyone in the lights of these pixels could offer free or cheap hosting for this site, please let me know.

The site needs a dedicated host, either real or virtual, with at least 1.5GB of memory and 20GB of disk space. It's bandwidth use is fairly modest, approximately 800MB of outgoing traffic per day at the moment (around 24GB per month). Incoming traffic is about half of that. However, we'd like room to grow in that regard, as I'm hoping we'll be able to increase usage over the next couple years.

We can take care of all the sysadmin bits, so all we need to start is a box running Ubuntu Hardy and the site will be good to go.

Thanks again to Eric and Xmission for hosting the site gratis all these years.