Categories / Programming
Premature Generalization

I’m trying to understand premature generalization. First, why is premature generalization a problem? Dave Smith:

One result of premature commitment to a generalization is that you’re supporting code that isn’t used. I’ve joined projects and found that 1/3rd of the code base wasn’t reachable, all because one or more programmers had tried to write class libraries that would solve all possible future needs. It is really, really tempting to give in to the misplaced belief that “… as long as I’m here, I might as well add the other methods that people might need at some point.”

2015-10-12    
Dockerizing Perl Applications

I presented at our Salt Lake Perl Mongers about using Docker to isolate dependencies in your Perl applications.

Perl on Docker

2015-09-14    
A Gentle and Mostly Harmless Introduction to Event Loops

I talked about event loops at OpenWest.

2015-08-05    
The Will to Design

Martin Fowler on the will to design:

In order to work, evolutionary design needs a force that drives it to converge. This force can only come from people—somebody on the team has to have the determination to ensure that the design quality stays high.

This will does not have to come from everyone (although it’s nice if it does), usually just one or two people on the team take on the responsibility of keeping the design whole. This is one of the tasks that usually falls under the term ‘architect’.

2015-07-15    
AnyEvent Primitives

I gave a talk at OpenWest about Perl’s AnyEvent module and some of its primitive operations.

2015-07-06    
Fast Perl Dependency Isolation

I gave a presentation at OpenWest about Perl dependency isolation using perlbrew and plenv + carton:

2015-06-01    
Perl Hash Reference Partial Copy

Given a multi-level deep hash reference:

my $conf = {
    bucket => {
        list => {
            h    => 'help me',
            _sub => sub { say "something" }
        }
    },
    file => {
        upload => {
            h    => 'help me too',
            _sub => sub { say "else" }
        }
    }
};

We want to remove all of the _sub keys and put them in a separate hash reference with the same structure. This does that:

2015-03-28    
Perl Dependency Isolation

I gave a talk about Perl dependency isolation at Salt Lake Perl Mongers.

2015-01-14    
Devel::Cover Notes

Some notes for using Devel::Cover.

Gathering coverage

CPAN::Reporter doesn’t have a build step, so we prove -l; we also don’t want to cover the world, so we set -inc=lib:

HARNESS_PERL_SWITCHES=-MDevel::Cover=-inc=lib prove -l

or:

PERL5OPT=-MDevel::Cover prove t/some-test.t

This will run the prove utility and turn on code coverage.

Selecting only one file to cover

cover -select=lib/Some/Module.pm

You may add multiple -select options.

Ignoring files to cover

cover -ignore_re=^/var/core_lib -ignore=/usr/bin/prove
2015-01-14    
Hashing to an 8-bit Integer

I needed to come up with a way to spread out chunks of a subnet among a handful of users, so I came up with this routine:

sub hash256 {
    my $str  = shift;
    my $hmac = hmac_sha256($str);
    my $val  = unpack "L*" => $hmac;
    my $hash = $val % 256;

    return $hash;
}

Used:

for my $str ( qw/scott paul mark jayce rvd james/ ) {
    say sprintf "%-15s %d" => $str, hash256($str);
}

Now the result of my $hash = hash256('joe') can be used as, say, the third octet in a cidr: 192.168.$hash.0/24.

2014-12-16