June 2007


Rated R for strong language

PHP, like most programming or scripting language allows for comparison operations bu using if/else. It’s a staple of any good language yet at the same time you can end up writing a lot of code in order to accomplish something very simple. Take for example this simple comparison:

if (empty($_POST['action']))
{
$action = ‘default’;
}
else
{
$action = $_POST['action'];
}

All we’re doing here is assigning one value to $action if the form variable action isn’t empty, and different variable if it is. This took up eight lines of code (OK, so you could argue that you could lower that by moving braces around but the code gets ugly fast). How can we clean this up? Enter ternary operators!
What’s a ternary operator you ask? In a nutshell, a ternary operator takes three elements and combines them into one. The basic syntax is (expression 1) ? (expression 2) : (expression 3); which means do expression 2 if expression 1 is true, otherwise do expression 3. It’s just an if/else condition rewritten in one simple line. Taking our previous example, we could consolidate it to this:

$action = (empty($_POST['action'])) ? ‘default’:$_POST['action'];

Voila! The exact same results in one easy to understand line. I am a huge fan of this shortcut and it comes in very handy when you have basic if/else conditions to check.

I can’t listen to the radio anymore. Free radio that is. I’ve had satellite radio for over a year now and it’s the only thing, aside from mix CDs, that I listen to in my car anymore. It’s obvious how the state of modern music has degenerated over the last decade or so. Now groups like Nickelback and Hinder, which sound damn near identical to me, plague the free airwaves.  Hate is a pretty strong word so I’ll just say that I can’t bring myself to listen to Nickelback, and their sound-alike counterpart Hinder. They’re horrible. I don’t know where to begin other than they’re the musical equivalent of a root canal. Even on the satellite radio shuffle channel I can instantly detect either of these talentless artists and when I check to see what’s playing, it’s inevitably one of them. Not to pick on these two bands but they need to do everyone a favor and pack up and go. There are arguable plenty of other talentless, fabricated musicians and bands out there that should join them. It’s rare to see an artist last for more than one album any more. Just look at the iTunes charts over the past few years and see what I mean. Oh and before you ask where I get off, I’ll just add that I worked with a Grammy winning musician for several years and leave it at that.

We are in a reverse renaissance.

Next Page »