logoGarden Of Blog


Unless

Posted in geek out by Marcus Del Greco on April 22nd, 2006

There is a command keyword in the Perl computer language called “unless.” It is used for conditional tests, when you’d like forego performing a set of actions unless a certain condition is met.

Some programmers consider using “unless” to be poor practice, because it flips conditional tests into a double-negative kind of thought process. The very same tests can be accomplished with the usual “if/else” constructs familiar to developers of almost any language.

But I like using “unless.” My brain seems to operate in this double-negative mode almost all the time. For instance:


unless ($salary eq "adequate") {
   lookForNewJob();
}
else {
   stayAndThrive();
}

or


unless ($all eq "well") {
   runAway();
}

It is a way of preparing for eventualities.

Still, there is a tension in needing to do such a thing. Wouldn’t it be nice to simply write…


stayAndThrive();

…with no conditions, because you know what you need to do, unconditionally? The stayAndThrive() routine is guaranteed to run, because there is no “unless,” there is no “if/else,” there is one true path to follow.

For this, no “unless…”

One Response to 'Unless'

Subscribe to comments with RSS or TrackBack to 'Unless'.

  1. RAMrozi said,

    on May 6th, 2006 at 12:50 am

    runaway(); has been very tempting lately, but without stayandthrive(); I would never have found out about podcasting or even working on an album of the month, it’s weird, ya never know where stayandthrive(); will bring you, but on the other hand runaway(); could bring other exciting options, so in the end, can you really tell which statement is better to run? is life really so scripted? maybe stayandthrive > runaway unless runaway > stayandthrive but then you’re just in an endless loop.

Leave a Reply