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.

Jun 2009

What Could Be Easier Than XML?

by in CodeSOD on

JT Klopcic could not believe his eyes. It was supposed to be a simple assignment. The length of some data field was changing, so he needed to walk through the import process and make sure that all the associated data sizes would accommodate the new length.

JT was unfamiliar with the process, so he took a look at the import file. Thankfully, it was all well-formed XML. This should be rather easy, he thought. And then he stumbled over this:


For The Love Of...

by in CodeSOD on

To many people, including Ron Owens, the word "some" refers to a relatively small amount in between "none" and "most". But To Ron's employer, and especially in the context of "job responsibly include... some maintenance of legacy VB6 applications", the word "some" tends to mean "pretty much all day long for the indefinite future."

Because legacy application maintenance is one of the torments found in the outer circles of hell, Ron had hoped to find catharsis by sending in examples of his day-to-day. But alas, because the application was so large and had been maintained by so many people, there was no single, concise snippet that faithfully represented what he was dealing with. That is, until recently, where he uncovered a snippet that not only illustrated the (over)complexity of the application but offers glimpse into what the UI looks like.


Simple SQL

by in CodeSOD on

John N's colleague's approach to problem solving is best described as follows. The solution to any given problem is to introduce two additional problems. While this approach generated quite a many interesting implementations, it rarely produced the needed results: simple, custom software for their clients. Ultimately, this approach led towards his de-hiring, which meant that John would have to maintain his old systems.

One project that John inherited was a fairly simple web application that tracked overtime. Simple, that is, from the front end. The back end PHP code was responsible for querying a MySQL database with queries similar to this:


The Int Divide

by in CodeSOD on

Mark Baker and Aaron Jenkins had one thing in common: they were both in the midst of a transition at Initech Global. It was Aaron's last day on the job and Mark's very first, and Aaron was tasked with helping Mark get acquainted with the applications, servers, and whatever else a new employee might need.

Of course, seeing that it was Aaron's last day, Mark's "brain dump" consisted of a single item: how to unlock the front door and disarm the alarm system. "So let's see," Aaron explained, "if you're the first one in, just put this here key into this here lock and give it a turn. Got it? Then punch 8863 on the alarm panel. Got it?"


A Waste of Time

by in CodeSOD on

Every now and then, you’ll come across some code that’s just like a car crash. The twisted, mangled-up kind of crash where the car’s on its side – possibly even on fire – and you can’t help but stare at the wreck with a mix of disgust and interest. Can it be fixed? Hmm, maybe something can be salvaged from the mess. Sheesh, I hope no one died as a result of this.

Samara N recently came across some car crash code: there were virtually no comments and the documentation simply read “handles time.” It came as no surprise that the code was written by Jared, also known as the Lead Developer’s sister’s daughter’s boyfriend. As everyone knows, nepotism rarely generates anything good, and in this case it generated something god-awful that no one dared to touch.


Interesting Bitmap

by in CodeSOD on

As a programmer for a steel mill, Josh gets to see all sorts of interesting things. And not the "everyday" things like the gargantuan ladles that carry hundreds of tons of molten steel. Or the red-hot, 2000°F slabs flying through the hydraulic rollers in the hot strip mill. Or even the giant vats of hydrochloric and sulfuric acid used by the pickler. No, I'm talking about The Code.

The Code — the lifeblood of the steel mill's information system applications — was originally developed by a highly paid consulting firm who specialized in the manufacturing industry and hired "only the brightest of developers". And that turned out to be their downfall: given the boring nature of the steel mill's information systems, the developers often made things far more complicated than they needed to be.


How Not to compareTo()

by in CodeSOD on

"With more changes being requested by the business and less time allowed to turn around those changes, we've fallen a bit behind on our deadlines," writes Zarar S, "so I requested that we bring on a contractor to help fill in. It was a long shot, but hey, anything not to come in to the office weekend after weekend."

"Amazingly," Zarar continues, "the Powers That Be granted my request and added a 'twenty-year veteran' with 'great Java experience' to my team. One of the first things I asked him to do was write a compareTo() method on our Activity classes and integrate them into our reporting subsystem. After a day or so of hard work, this is what the expert came up with."


Illogical Logic Flow

by in CodeSOD on

"I took a job at Initrode Software to help build the bridge to C#/.NET from their current, VB6 codebase," Chris G. writes. "It didn't take me too long to realize that the original programmers of this software — the only product that Initrode sold — had very little real-world experience."

"Recently," Chris continued, "I was fixing some of the code that was used to highlight a portion of the screen when I found this."