Pensieri di un lunatico minore

18 July 2005 Technology

A personal WTF

Everyone once in a while, you’re reading along in someone else’s code, and find some bits of thought-process that just make you scratch your head. For your enjoyment, I present three, slightly munged to hide the origin, from the same stream of code:

if ($foo == "")
{
    $foo = return "empty";
}

and, slightly less WTF, and more “do you understand arrays and control structures” is this bit:

($one, $two, $three, $four) = split(/\./, $this);
$one = int($one);
$two = int($two);
$three = int($three);
$four = int($four);
if ($one eq "") {
    $one = '0';
}
if ($two eq "") {
    $two = '0';
}
if ($three eq "") {
    $three = '0';
}
if ($four eq "") {
    $four = '0';
}
$new_this = "$one.$two.$three.$four";

or maybe you prefer the duplication of everything to “theoretically” save referencing an array?

@items = split(/\s/, $big_string);
my $count = 1;
foreach (@items) {
    $itemName = "item" . $count;
    $$itemName = $_;
    $count++;
}

And there you are. The joy of editing someone else’s code.

This entry was posted at 4:14 pm on 18 July 2005 and is filed under Technology. You can follow any responses to this entry through the post-specific RSS 2.0 feed.

Good God. That is wretched.

I can’t decide whether to shoot myself or offer the bullet to you instead, out of pity…

So I shouldn’t tell you that this is part of a file that is nearly 300K in size and is one HUGE if/elsif chain?

Not without immediately handing me a bottle of aged Scotch afterwards, no.

Many things are made better with aged Scotch. This might just be one of them.

I find a bottle of aged Scotch and a demagnetizer fix this one.

Both comments and pings are currently closed.