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.

May 2013

Now Wait for Next GetYear()

by in CodeSOD on

Bob was watching the sales telecast for WidgetCo when his boss approached him. “We got a big problem, and it needs to be fixed fast.” Before Bob could object, she grabbed his laptop and ushered him down the hall.

The VP of Sales stood outside the conference room where the telecast was taking place. He shoved a tablet under Bob’s nose, which showed a line graph of WidgetCo’s sales from January 2012 until now. The graph took an enormous plummet on January 1, 2013. “Son, this has got to be fixed, or I won’t have a graph to show our record sales!”


The More Things Change...

by in CodeSOD on

Change. It's something we all live with every day. We change our clothes, jobs and sometimes even spouses. Change can be a good thing. Some say not to fear change, but to embrace it! Wisdom tells us to always be prepared for change. Bill U's company likes to be prepared for change.

They have a lot of DAOs to access the data in his company's database. There is a base class that can be extended to make it easier when writing all that annoying, pesky SQL. This class has some helpful functions for getting and closing connections (sane stuff), and then there are the constants for SQL 'literals'. The class contains some helper functions where the constants are used, and some other functions where the constants are not used. This way if they change the database vendor and the definition of a SPACE changes, they can mostly just fix the constants and the data layer will still work.


The Truth of the Matter

by in CodeSOD on

When Ben found this block of code, he had some questions: who wrote it, and what was it supposed to do?

if (showOptionsButton == true)
   showOptionsButton = false;
if (showOptionsButton == false)
   showOptionsButton = true;

Habla Currency

by in CodeSOD on

Adam worked for a company that sold check printing machines. It was not a particularly large company, but the machines were cutting edge when it came to the latest and greatest technologies to prevent check fraud. So while the company was doing well enough, until now the company was selling equipment solely in the United States. At least, that is, until one of the more enterprising sales people decided to ‘branch out’.

In this case, the branch was a small Mexican bank. It was not known how the salesperson even made contact with the bank. There were rumors flying around that it involved a drunken night in Cabo and a lost wager in a cock fight. And maybe a tiger in a bathroom. But none of this is germane to Adam’s story.


The Impossible Blob

by in CodeSOD on

BlobConfig.config not found, said the error console of The Blob-- the "insane in every way" system Sep's company produced.

Because a millisecond earlier, The Blob erroneously determined Sep's computer already had a copy of the config file, and didn't automagically create it.


A Cascade of Failure

by in CodeSOD on

Ben sent in the following snippet from a PHP site. His description of the site as a whole is unpublishable in most countries, but among his frankly shocking profanity he pointed out a lack of error checking and comments, and an abundance of unreadable inline code and confusing, unnecessary functions.

When Ben tried to describe the following routine though, he broke down, weeping openly. While we wait for him to regain his composure, let's ponder the depth of wrong present in this code:


Re-Inventing the Alphabet

by in CodeSOD on

Michael listened as his co-worker Draughon droned on at lunch. "I just don't trust hashes, man. I never understood any of the algorithms behind them, and I don't trust anything I don't understand."

"But MD5 is a well-documented algorithm," Michael countered.