Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Sep 2007

When an Enum's an Enum

by in CodeSOD on

Barry R. and Rob P.'s coworker had a problem: how could he really, really make sure they verify that a value stored in an enumeration, say the EmailsFormat enum, is actually a valid value for that enumeration? With the handy FromEmailsFormat function of course!


containsNotEqualBackwards

by in CodeSOD on

Ahh, the things you can find in an old, gigantic system! Chris B recently uncovered this gem in an old Java application. It might be misnamed, but then again... how could one possibly describe what this is supposed to do...


All For 19 Seconds

by in CodeSOD on

Date and Time computations aren’t easy. Unless you’re fortunate enough to use Metric Time, there are a whole lot of uneven measurements to work with. Sixty seconds in a minute. Twenty four hours in a day. Thirty, thirty one, twenty eight, maybe twenty nine days in a month. Fifty two point something weeks in a year. It’s just ugly.

Fortunately, just about every programming language out there has library code to help with the math. Naturally, many “certain” programmers chose to ignore this library code and hack their own. Like Yuri’s predecessor. He was presented with a simple problem: add nineteen seconds to the current date/time in Perl.


Ph33r my 5k1llz!

by in CodeSOD on

I hate the final stretch of a project; it's when all the minor bugs that I've been putting off fixing need to get fixed. An anonymous submitter that we'll call Scott was brought on for the final round of fixes of a large, vendor-built application.

Scott's first task was to fix a simple little issue in the admin section of the site. He opened the project and read an ominous line of code right at the top of the file:


Only $0.001 per Line

by in CodeSOD on

Generally speaking, $300 doesn’t go very far in the world of custom software. If you’re lucky, it might be enough to fix a typo in a production application. These days, with the advent of IT Project Portals (as discussed before) that provide everyone access to certain developers from certain countries, $300 can go a long way. Not long enough to build working software, of course, but surely long enough to generate lots and lots of worthless code. At least, that was the experience with Christopher’s client.

Christopher’s client is a large (as in, one of the “Big 5”) advertising firms that decided to initially place their RFP for a survey application on an IT Project Portal. A few months and $300 later, they ended up with about 500 PHP-files (31 of which are class files without any members) and a database schema that stores all values in VARCHARs. And it all “almost worked.” Fortunately, they had Christopher to help “debug” it.


Old Fashioned Web Services

by in CodeSOD on

When users upload a multimedia file to Toti S.'s company's website, their system transcodes the file into several different multimedia formats. At the high level, it's a pretty basic process.

1. User uploads file to Upload Server
2. Upload Server notified Transcoding Server via an XML request
3. Transcoding Server reads XML request and does its thing (creating various sizes/flavors of multimedia content)
4. Transcoding Server uploads various files to the Main Server


Class Ego

by in CodeSOD on

Sometimes, there just isn’t a better way. You have to implement the DoNothing() method. Or even IsTrue(). At least, that’s what D.C. assumed when he saw a a class with a member variable named “self” …

 


How Did No One Think of this Before?

by in CodeSOD on

Matt found a less-than-helpful helper function in a large JavaScript library:

function confirmMessage(msg)
{
    if ( confirm(msg) )
        return true;
    else
        return false;
}