December 2010 Archives

Role::Basic - When you only want roles

A long time ago I posted about Roles without Moose and while I still feel that for most cases Moose is the way to go, there can still be a bit of resistance to the idea. Matt Trout responded to my post with how one could have just roles (read his entire post to understand the context):

package Foo::Manual;
use Moose;
extends 'UNIVERSAL'; # get rid of Moose::Object

with 'Foo::Manual::Bar';

sub new { bless {} => shift }

This still involves putting Moose on your servers and when you're faced with a large dev team that is very conservative in their approach, this might be an uphill battle. So what are my alternatives?

A Desired SQL Affordance

When talking about an affordances, it turns out that there are different definitions, but I like to think of an affordance as "an element of design which suggests the correct course of action", which seems to be pretty much what Donald Norman meant when he adopted the term. It's an elegant concept which, if applied properly, makes it easy to do the right thing and harder to do the wrong thing. However, sometimes you want to do the wrong thing, so an affordance which makes this impossible isn't the most useful in my book. I just want doing the wrong thing to be jarring enough that it would give anyone pause.

And this brings me to the following issue I often see in SQL:

SELECT count(*) 
  FROM employee 
 WHERE salary < 20000;

If salary is allowed to have a NULL value, then employees with a NULL salary won't be included in this count. If you're familiar with SQL, you will instantly know why. However, even those familiar with SQL sometimes fall into a trap here because they think "hey, why didn't I count the unpaid volunteers?"

There's a very simple way of removing that trap, but I seriously doubt anyone will ever implement it.

Perl101: Red to Green Gradient

Note: the following technique is not friendly to the color-blind.

I sometimes find that I want to visual data with color. Specifically, I want to use red for "bad" and "green" for good, with a linear gradient in between. As I'm often building Web pages, that means I want:

Color codeResult
#FF0000Bad
#FFFF00Bad-Average
#FFFF00Average
#7FFF00Average-Good
#00FF00Good

In other words, I want a smooth, linear gradient from red to green for any number in a range. I'm always hitting a search engine for an example, so I figured other people could use this, too.

Quiet

In case you're wondering why I've been rather quiet (for me) lately, it's due to my expat blog. I'll post here again, but I'm trying to get a lot of content up there for wanna-be expats.

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/