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.

Feb 2012

DATE_NOT_FOUND

by in CodeSOD on

So it’s once again February 29... that one time every four years when newspapers do their fluff pieces about people who only have a birthday every four years, and you find all kinds of obscure bugs in your code. I managed to save two examples from the last leap day that I thought would be best shared today.

The first is from Eric, who wrote "my client is an alcohol company, and I run their website. They have a members-only section of their site that requires that you to enter your birthdate. If you're less than 21 years old, they kick you out and won't let you onto the site until you come back on and lie about your date-of-birth."


The Regex Code Review

by in CodeSOD on

Ding! A new e-mail appeared in Jed's and the other developers' inboxes on the floor. It was from his coworker Bob, and it read:

"Jed, the term-validation process of CAPBACS is a performance bottleneck that's costing our company thousands in lost sales every month. This change must go in ASAP. While I appreciate your feedback and input, I don't believe that your experience working on the Web places you in a position to critique my work. Thanks!"


The Phony

by in CodeSOD on

"My first impression of my predecessor was a positive one," writes Michal Ochman, "he was well-spoken, sharply dressed, and seemed to be an all-around nice guy."

"My first impression of my predecessor's code was also positive — it was sanely structured, well-commented, and all-around seemed pretty clean. And then I started actually looking through it. It was filled with a lot of... well... this."


The Sentimental Query

by in CodeSOD on

After weeks, months, or even years of setting up and preparing to sell, it’s always exciting to get those few customers. Depending on the venture, it may not be worth popping open a bottle of Champagne, but no matter how small the sale, one can’t help but take a few moments to pause and smile before struggling to get that next batch of sales.

By the time the 13,853rd customer rolls around, no one blinks an eye. It’s just business as usual. That is, unless you work at Ruben’s company. When a new customer record is created, their server not only takes a moment to celebrate, but it nearly brings down the entire server with this unique way of finding the next available customer number:


The Lemming Switch

by in CodeSOD on

"The way in which project requirements meet developers at our company is a WTF in and of itself," writes Kevin, "but suffice it to say that a certain developer was tasked with writing a Windows Service that would periodically review a list of files from the network and purge them if necessary."

"Of course, to this certain developer, 'Windows Service' means something that is left running on a desktop somewhere. In his world, VB6 is also a 'simpler, cleaner, and easier to use' platform, and thus is his platform of choice... to this day. Here's what he delivered after a couple days of work."


The Applet Redirect

by in CodeSOD on

"One of our sites is partially maintained by a third-party vendor with developers based out of Kerbleckistan," writes Nathan, "they'll sometimes 'forget' to use version control and instead just write directly to production. This has naturally caused some frustrating 'lost feature' problems when they remember to use source control, and somehow this all falls on me to mitigate."

"To avoid constantly breaking things, I wrote a script that monitors file changes to production and commits any changes to a branch in the repository. I'll then merge their changes into the working mainline. It's usually a few JSP files with some text or a link updated, but recently, when I went to fetch the current status, I was greeted by this friendly result:


SQL MUGging

by in CodeSOD on

"We're replacing an old PHP website," writes Roggo, "to examine the existing functionality and test the install, we were given access to the live site. Out of curiosity, I had a look at the code that we are soon to replace. The first file I opened was called mug_password_forgotten.php; I was greeted by line 8:"

$sql = "select muguser_id, muguser_directory " . 
       "from mugusers " . 
       "where muguser_active = 1 " . 
       " and muguser_email = '" . $_POST["email"] . "' ";

Dirty Code

by in CodeSOD on

Ever since being hired, Adam had spent most of his time working on new projects.

He was aware that there was an "old system" running out there and would someday be shut down and his efforts were to help this come about, but he never had the opportunity to cross paths with it.  Based on what he had heard though, this was a very, very good thing.


The Percent Conversion

by in CodeSOD on

"Lucky me," writes Joe from the Submit-To-WTF Visual Studio Add-In, "I just inherited a home-grown system information application."

"Judging from the code the previous programmer wrote, this is sadly one of the better pieces."