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.

Aug 2011

The String Padding Trick

by in CodeSOD on

"Our system prints out its share of reports and thus has to deal with its share of string padding," writes Jon B.

"There are many, many ways to pad strings with spaces, but our developers has chosen to go use this 'trick' to do it. Here's one example, where a particular field needed to be padded to 30 characters... or perhaps 35"


The Rockstar's Guard

by in CodeSOD on

"Someone introduced me to The Daily WTF back when I was a freshman at university, and I've been reading it ever sense," writes Patrick, "I was convinced that most of the bad code was made up or exaggerated, and that I'd never have the horrifyingly irresistible compulsion pleasure of submitting bad code."

"However, now that I'm in the real world, and getting settled into my new job at certain, large financial services provider, I've started reviewing their codebase to get a feel for how they do things around here. Though the codebase was an uncommented beast conjured up through outsourcing to Kerbleckistan, none of it was quite WTF. At least, until I got to the code written by our in-house rockstar.


God Date Mangling 101

by in CodeSOD on

Lori's coworker was a PHP God. His computer was named godbox, which matched his login name of god. A project that took other developers three month to finish, he was sure he could do in three weeks. On one such project, his code utilized all the power of CSS, JavaScript, PHP, and ImageMagic all to generate one graph, that's supposed to show the last 3 month of data.

In this project, each row in the table below represented a row of data per month.


The Alumni Variables

by in CodeSOD on

"Not too long ago," Aaron writes, "I applied for a Java developer position at a certain, prestigious university. Despite passing the technical assessment with flying colors, the department head rejected my application because, according to the recruiter, 'he really only hires alumni'. Eh, whatever."

"A few months later, the same recruiter called to see if I'd be interested in an interview. One thing led to another, and I ended up taking the job - apparently, the alumni Java developers they hired ended up making a bit of a mess of things. Upon my first look at the code, I saw a comment that said Create all the variables. What was beneath it was, in fact, all of the variables:"


Top-grade, SHA1 Encryption

by in CodeSOD on

Paul B always thought of himself as a moderately-paid consultant. With no real overhead, a policy against ties when meeting with prospective clients, and a general pickiness about the projects he'll take on, his rates tend to be pretty low. One company that looked right up his alley was a mid-sized manufacturing company that wanted a custom webshop. They went to the highly-paid consultants in town, but weren't too happy with the six-figure price tag. Paul's quote was in the five-figure range, which he felt was pretty moderate given that it was a several month project. Of course, the company wasn't too happy with his quote either, so they searched high and low for a three- or four-figure price. They eventually found one overseas.

Despite losing the bid, Paul never bothered unsubscribing from the company's mailing list - there was always something exciting about learning the latest in gimbal clamps and engine nozzle extensions. About a year and a half later, he received an exciting newsletter announcing that the webshop was finally live. Out of curiosity, he created an account to check things out. A few days later, he received an apology for lost orders - they didn't know who had ordered what, so they sent it to everyone who had signed up. And then came the "data breach" email — everyone's personal data (which, for Paul, was just his throw-away email) was now in the hands of some hackers. You get what you pay for never rang so true.


The Phantom Duo's ChangeWord

by in CodeSOD on

"I spent almost a year of my life working with The Phantom Duo," writes David B via the Submit to TDWTF Extension, "while their tenure resulted in a lot of headaches, a few lost jobs, and a multi-million dollar explosion, there was one positive result: lots and lots of bad code."

"At least, that's a good thing for me, since I haven't worked with the code in years: it's like I have my own, personal The Daily WTF archive on a flash drive. This particular method seemed worth sharing - I even added a few comments to help understand it."


The French Disconnection

by in CodeSOD on

"The application that I've been assigned to had a fairly common requirement", writes Shaun H. "It needed to be bilingual, supporting both French and English."

"I've worked on quite a few multilingual apps before, and have a lot of different patterns and anti-patterns, ranging from using a resource file for strings to copy/paste/translate. Now, I can add this Oracle-based function to the list."


Manually-propagating Worm

by in CodeSOD on

Ivan Montilla writes, "those of you who use Facebook have probably seen spam like Check who visited your profile and the like. It's almost always either a scam of some sort or a ruse to get you to download some malware."

"Recently, I came across a friend who had proudly become a fan of Check who visited your profile, 100% Working. And then another friend. And another. Wondering if it was a new type of mischievous worm, I disabled all scripting and viewed the profile. The first thing I noticed was that it prompted you to download a .vbscript file, which definitely wasn't a good sign. I opened it with Notepad to find this:"


An Enum or _2

by in CodeSOD on

"The company I recently started at creates products for military and law enforcement use," writes John, "naturally, fixing bugs is a high priority for us in the software department, despite the legacy code we have to work with."

"One day, when I was feeling especially masochistic, I thought I'd run our code through FxCop, a static analysis tool to see what came up. As I was scrolling through the infinity billion warnings, I noticed one about an enum I had never seen. So, I clicked on the warning to find this:"