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.

Oct 2010

Double Spaced

by in CodeSOD on

If past CodeSOD articles are any indication, it would seem that "certain" developers have a very difficult time wrapping their minds around spaces and spacing.

How do you replace double spaces? What about triple spaces?? Or quadruple??? Clearly, these were questions asked by the coders of today's two specimens. And obviously, they found their answers.


It's Not A Bug, It's Data Security

by in CodeSOD on

"I work for a nationwide retailer," Jody writes, "In one of the databases I work with frequently is a table called PRODUCTS which contains information about every item we sell, and on this table there's a trigger called PRODUCTS_TRIGGER which fires on every insert, update, or delete. One day while working on some unit tests I needed to insert a row into PRODUCTS, work with it, and then delete it when the test was complete, but the DELETE failed because of a problem in PRODUCTS_TRIGGER. When I looked at the code for this trigger I found the following sequence of comments:

    -- <name redacted>  mm/01/yyyy  This trigger was preventing deletes because
    --                              it's trying to insert NULL into the primary
    --                              key of the PRODUCTS_AUDIT table on DELETES.
    --                              Corrected problem by using :old.PRODUCT_ID
    --                              (which has a value) instead of :new.PRODUCT_ID
    --                              which is NULL when doing a DELETE.
    -- <name redacted>  mm/10/yyyy  <Name of VP in charge of security redacted>
    --                              insists this trigger be changed back to how it
    --                              was to "prevent a rogue process from deleting
    --                              products".

The Intern's Internet Disorder

by in CodeSOD on

It was the start of summer and Stephen was almost as excited about college junior Nathan's internship as Nathan was. Stephen’s company had a history of selecting new employees from their small group of fresh interns that started each summer and Nathan seemed like the right guy for the position.

To get his feet wet, Nathan would be first assigned to the SEO group where Stephen would be overseeing Nathan’s work. Though the SEO team was small when compared to the rest of the web development group, Nathan was in a position to make a big impact on driving traffic to the sites that Stephen’s company maintained and add a nice set of bulleted items to his resume or, if things worked out, a full time job after graduating from college.


Overloaded Help

by in CodeSOD on

"A certain coworker of mine is known for writing vast libraries of redundant Java code (example: makeStringArray(...)) in the hopes it will make everyone's lives easier," Jared writes. "That said, I wasn't at all surprised when I encountered this block of code."

"What's notable, however, is that when I first saw it, there were only 10 overloaded versions of setRecData(). I made the mistake of sarcastically asking him, 'but what if I have to set record data for twenty sets?' The next day, the improved version you see here was committed."


Property Basics

by in CodeSOD on

Whenever a Code SOD featuring Visual Basic is published here, a flood of The Real WTF is VB comments ensues. As mindless and unoriginal of a comment as it is, there's a good reason for the sentiment: Visual Basic is designed for beginners, is often used by beginners, and beginners write an awful amount of awful code.

While it's easy to blame the language for bad code — *cough*PHP*cough*variableVariables*cough* — beginner-targeted languages can offer some benefits. Like, for example, the awesome fun and ease of using a single line of code like this: My.Computer.Audio.Play("cha-ching.wav")


Cold Date Conversion

by in CodeSOD on

"Our customers were reporting a strange bug," Eric writes, "when they would select dates for events in December, they'd get the following message."

Conversion failed when converting datetime from character string 'De/09/2010'

The Why Timeout

by in CodeSOD on

Slade's colleague had a hard time grasping why. It wasn't that he was slow, more that he just didn't care enough to think things through. In some lines of work that’s not too bad, but in software development, it can lead to “interesting” results. Case in point: a timeout dialog.

The task was to detect whether someone forgot to log-out of the application and, if so, log them out of the system. This was an important feature, as the application was responsible for divvying up time-sensitive data analysis work. The first attempt was pretty straight forward:


Tweaking the Code

by in CodeSOD on

It wasn’t that Jim minded initiating interns into the world of web development, in fact, he viewed the challenge as a very satisfying experience. However, when the newest intern, Stefan, declared on his first day “I don’t want to be labeled as programmer for the rest of my life. Programming sounds too nerdy. I solve problems.” and that despite his ColdFusion experience, he had previously hosted raves and dance parties in his younger days (to further distance him from any chance of being considered a nerd). In short, Jim knew that he had a special case on his hands.

Rather than bruise Stefan’s apparently sensitive ego and give him an assignment that might involve invoicing or user security auditing, Jim handed Stefan a technical, yet practical, task - write a program to get the daily weather reports from a government website and store them locally so that users could see a cached copy rather than pulling it off the weather website each time.