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.

Dec 2007

Classic WTF: Implements ISwissArmyKnife

by in CodeSOD on

Although I've taken the rest of the year off, I wanted to share a few fun classics this week. "Implements ISwissArmyKnife" was originally published on 2005-02-24, and never seems to grow old...


I have yet to find someone who doesn't love Swiss Army Knifes: you know, those multi-function thingies with a few blades, a screwdriver, scissors, and a pepper grinder? Well, as surprising as this may be, the concept behind this Macgyver-saving-tool doesn't work well when applied to software development. But you gotta give Rick Harris' colleague some credit for trying ...


Classic WTF: Because database drivers can be too complex

by in CodeSOD on

Although I've taken the rest of the year off, I wanted to share a few fun classics this week. "Because database drivers can be too complex" was originally published on 2004-07-09, and is just one of those WTFs you wish you could un-see...


I was pretty stoked to see this submission from Stian Søiland. We've all seen developers do all sorts of crazy things, from completely avoid regular expressions to not bothering to use INNER JOINs or even basic WHERE clauses. But this?!? I think takes the cake ... or at least comes pretty close ...


Classic WTF: Now That is a Way to do States

by in CodeSOD on

Although I've taken the rest of the year off, I wanted to share a few fun classics this week. "Now That is a Way to do States" was originally published on 2005-01-31, and amazingly, no one has submitted a worse way to "do states" to this day...


It's hard to believe, but a good seven months ago, I honestly thought that using an autonumber as the primary key (instead of OH, NY, etc) was a bad way of implementing a States table in a database. Of course, thanks to everyone who's submitted things over the months (you guys rock, by the way), tblState would simply have been tossed in the "not using best-practices" category. But I think we can all agree that this state-handling routine from Kurt Payne would definitely fit in the Whisky Tango Foxtrot category ...


Classic WTF: The Brillant Paula Bean

by in CodeSOD on

Although I've taken the rest of the year off, I wanted to share a few fun classics this week. The Brillant Paula Bean was originally published on 2005-08-05, and never seems to grow old...


Heidi S and Michael Hanson's employer was building an enterprise shipping/warehousing system but didn't have enough in-house resources to do it. One of the contractors they brought in to help fill the gaps was Paula, an "experienced Java programmer with strong knowledge of the shipping industry." For the first few months, things seemed to be going pretty well. At the weekly status meetings, Paula would report that good progress had been made and things were looking good for the deadline.


Classic WTF: What Is Truth?

by in CodeSOD on

Although I've taken the rest of the year off, I wanted to share a few fun classics this week. What Is Truth was originally published on 2005-10-24.


The problem with "logic" is that it makes things out to be nothing but simple dualities. Proponents of logic want us to believe that everything is true or false, black or white, yes or no, paper or plastic, etc. Thankfully, there are some among us, like Mark Harrison's colleague, who are not afraid to stand up to these logic advocates and shout "no, I will not succumb to your false dichotomies!" Today, I think we all should salute those few brave people ...


Reverse Brute Force

by in CodeSOD on

When David was approached by a colleague for an estimate on some PHP work, David insisted that he'd need to see some of the code first. The only background David had on the project was that it was a PHP site with a MySQL backend, and a pretty sizable user base.

When David received the code, the first thing that he noticed was an unreasonably large file called namelib.php. It was apparently intended to clean up users' first names...


The Most Thought Out Enumeration

by in CodeSOD on

When Chris M's company finally decided to rewrite portions of their decrepit C++ application, Chris was relieved. "Finally," he thought, "no more ridiculous, unnecessary classes and enumerations."

The DlYesNo enumeration, as featured in Not the Most Thought Out Enumeration, was one of many of such “unnecessary classes and enumerations.” Chris figured that the new, cleanly-programmed J2EE application would have none of that.


A Null Understanding

by in CodeSOD on

These days, having written about bad code for a few years now, it's pretty rare to uncover a new anti-pattern like the FOR-CASE paradigm, IHBLRIA, or RLB o'PCC. However, having seen snippet after snippet like todays two, I think it's finally time to identify the Null Understanding...

Daniel found this snippet during a code review that was left by a senior developer who, thankfully, is no longer with the company.


No Loop For You!

by in CodeSOD on

When Mike's coworker left the company for greener pastures, Mike got stuck with maintaining all of his old projects. This wouldn't have been too bad if it weren't for a application that was developed using the BrillantML (as I'll call it). While Brillant ML is technically a programming language, a more apt description is "a few commands surrounded by an XML wrapper." Yes, it really is as horrid as it sounds.

BrillantML is used to create interfaces on a certain type of consumer hardware, and Mike's first experience with it was when he needed to change some of the menu labels around. The first thing he noticed was his predecessor didn't believe in using loops. Anywhere.


It Only Seems Redundant and Stupid

by in CodeSOD on

Isaac S. recently started working for a certain online multiplayer game company, and noticed that his fellow developers were very meticulous about security.

"Concerned that hackers might try to break into the game servers," Isaac wrote, "they encrypted the IP-address when it was passed between functions using XOR encryption. It was the perfect protection against hackers that didn't have Netstat or any other network sniffer."


What If Someone Types In " "?

by in CodeSOD on

Bob T. got sucked into one of those "maybe the new guy can figure it out!" problems, only to open the first page - and then subsequent pages - to see that all of the validation code looked like this...


It Had Too Many Functions

by in CodeSOD on

As one of the more experienced C# coders in his group, Yakir is often asked programming questions. Recently, his colleague James asked him the best way to store hundreds of thousands of items in memory, to which Yakir replied "It depends on how you want to access your data. If you want to access your data by index, you should store it in an ArrayList. If its easier to store things as a key-value pair, then you should use a Hashtable."

James' particular application called for a Hashtable, so he decided to implement that. A few hours later, however, he ran into some trouble. "This Hashtable isn't really working," James explained, "do you know if there's something more efficient?"