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.

Jul 2016

Exit Thread

by in CodeSOD on

Objects left in the garage or the attic tend to multiply. If you don’t clean them regularly, you find mysterious and inexplicable things have bred like rabbits. “Why is there a bag of marbles in this box, and when did I ever buy an ugly Christmas sweater?”

Without regular refactoring, the same thing can happen to your code-base. Michal is finally taking a look at a bit of code that hasn’t been touched since 2001. The original developer has left the company, there’s no documentation, and the SVN history has long since been discarded.


It's Log, Log, Log

by in CodeSOD on

Logarithm keys

Reader Bernie submits for our approval this wonderful C# log base 2 implementation. He says: “We can distinguish two halves in that code. It looks like it was originally written for an unsigned 16-bit int, and later on extended for signed 32-bit integers.”


OhgodnoSQL

by in CodeSOD on

How about those NoSQL databases, huh? There’s nothing more trendy than a NoSQL database, and while they lack many of the features that make a traditional RDBMS desirable (like, um… guaranteeing writes?) , they compensate by being more scalable and easier to integrate into an application.

Chuck D’s company made a big deal out of migrating their data to a more “modern”, “JSON-based” solution. Chuck wasn’t involved in that project, but after the result went live, he got roped in to diagnose a problem: the migration of data from the old to the new database created duplicate records. Many duplicates. So he took a look at the migration script, and found piles of code that looked like this:


Lunatic Schema-tic

by in CodeSOD on

One day, James’s boss asked him to take a look at a ticket regarding the “Cash Card Lookup” package, which had an issue. James had no idea what that was, so he asked.

“I don’t know,” his boss replied. “I just know the call center uses it. You’ll need to talk to them.”


Hanging By a String

by in CodeSOD on

We all know that truth is a flexible thing, that strict binaries of true and false are not enough.

Dana’s co-worker knew this, and so that co-worker didn’t use any pidling boolean values, no enums. They could do one better.


Classic WTF: RegExp from Down Under

by in CodeSOD on
This particularly bad example of regular expressions and client side validation was originally published in 2009. I thought Australia was supposed to be upside down, not bass ackwards. - Remy

"The company I work for sells vacation packages for Australia," writes Nathan, "and for whatever reason, they're marketed under different two different brands — redacted-travel.com.au and redacted-travel.com — depending on whether you live Down Under or somewhere else in the world."

Nathan continues, "one of the requirements for the international website (redacted-travel.com) is to disallow people from within Australia and New Zealand to make bookings. But the way this is done from the front end... well, it's a real gem."