I was working on some code today when I noticed the following two conditionals:

if ($po->status->name eq 'Pending') { # po can be sent } # later if ($po->status->name eq 'Pending' || $po->status->name eq 'Sent') { # po can be cancelled }

Ugh! What horrible code. If we need to change those names, this code will be break pretty quickly. We'll also have to hunt all over our code base for instances of code like this. If we need to check the value of an object's properties, push it back into the object.

if ($po->can_send) { # po can be sent } # later if ($po->can_cancel) { # po can be cancelled }

Much nicer :)


New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)