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.

Jan 2012

The .NET Whistleblower

by in CodeSOD on

Terry had spent the better part of the past decade digging through the trenches of QuidCorp's flagship application QuidFlow -- a program used to flowchart business processes. Though QuidFlow performed well and, overall, customers were happy with the product, whenever it came time to address a bug or investigate just how the filename validation worked; the source code was beginning to show its age.

Terry raised his concerns to management. Much to his surprise, management approved a plan to transition their C++ developers into the world of .NET through a little on-the-job experience.

Homemade with Love


Globally Coupled

by in CodeSOD on

"I work on a team maintaining a large and enterprisey PHP system," writes Amber, "and as such, my job mostly involves doing enhancements and fixing bugs."

"It sounds normal enough, if not for the fact that almost all variables are globals and each of them might or might not be initialized in the same way, or the same place, as seen in this screenshot."


Pluralized!

by in CodeSOD on

"When digging through some code that was on the refactor list, I came accross some validation logic that checks if the user selected enough options on the form," writes Chris Osgood, "if enough options weren't selected, you'd get an error message along that said something like 'at least 3 options are required'."

"It took a little bit of coding to get that validate message. The '3' was obviously dynamic, and if there was only one missing selection, then 'are' was replaced with 'is'. As for the word 'option'...it was is PLURALIZED!"


The XML Escape

by in CodeSOD on

"One day, our logistics analysis vendor interface completely broke down," wrote Ben Davis, "that's a Bad ThingTM, as our primary focus is to provide logistical services to our clients."

"Fortunately, it didn't take too long to track the problem down. Our vendor was sending over unescaped ampersands in their XML API."


Troubling Trouble Ticketing

by in CodeSOD on

"I'm not sure how he did it," writes Joey, "but one of my colleagues convinced management that we needed a trouble ticketing system. Since we had been using email and post-it notes for many years, it was a welcome addition to the team. Well, at least it would have been... had it not been a home-grown system written by Chad."

"The good news was that Chad had previous experience building such a system. The masterpiece of his previous job was a trouble ticketing system written entirely in VBScript that ran inside of Excel. After several attempts to make it work for us (it had a bad habit of only working on very specific versions of Excel) he decided to start clean using PHP and MySQL. A web-based system was a welcome alternative to a spreadsheet... at least, it would have been had Chad not recently learned about a 'new technology' called AJAX.


Nondeterministic Months

by in CodeSOD on

"There's been a lot of talk that 2012 will exclude the month of December," writes Jon-Paul Murrow, "you know, end of world, Mayan calendar, Nostradamus, and all that. Even if this doesn't happen, there's no guarantee that future years will have twelve months."

"Fortunately, I found this snippet of JavaScript in our codebase at work that will find the number of months in any given year (that's right, any, year)."


2012... Just Because

by in CodeSOD on

"Most people spend their New Year's Eve watching the ball drop and celebrating the New Year," writes Jason, "and actually, that's what I planned to do, too. Instead, I found myself debugging our licensing activation system." "Just as I was about to leave the office, I received a torrent of emails with the subject 'License Activation Failed'. One or two every now and then is expected, but dozens and dozens at four o'clock on New Year's Eve... not so good. It took me a moment to realize the significance of 4:00PM, but then it hit me: I'm on Pacific Time, which is UTC -8 hours.

"The error message that was filling up our logs was simply 'INVALID DATE' and for the life of me I couldn't figure out why. Our license code was a 32-bit number that represented the expiration date of the license and the features in the license. 7 of those bits represented the year since 2000, so obviously the date was fine up until 2127. After hours and hours of digging through PL/SQL, Java, JavaScript, Ruby, and some random shell scripts, I found the following.