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 2007

Inflammatory Comments

by in CodeSOD on

Once upon a time, there was a web programmer and a web designer. Try as he might, the web programmer was not a very good programmer: he hacked, and hacked, and hacked, but his programs just never worked the way he wanted. The web designer was a good designer, but had one problem: her ego was three sizes too big.

One day, the web programmer and the web designer worked together on a project. They had their arguments; they had their differences; and they made sure to discuss their arguments and their differences in the HTML comments for all, including Robert H, to see and enjoy ...


F'd Factorial

by in CodeSOD on

When we look to hire a recent college graduate, there’s not a whole lot we can expect. Source Control, Defect Tracking, Best Practices –all concepts not a part of any computer science curriculum I’ve ever seen, but essential in any business environment. All we can hope for is a good personality match, a strong potential for learning, and at a very minimum, some retention of the concepts taught in computer science courses.

On a recent interview, Richard’s candidate managed to score zero-for-three. Despite having recently graduated with a computer science degree, the student had a tough time solving the easiest of easy computer-science riddles: the Factorial. Their conversation went something like this ...


Multiplied Denomination

by in CodeSOD on

Hannes lucked out: he wasn't assigned to the .NET Migration Project. Of course, that doesn't mean he's free from it, as several hours each day, he hears the unmistakable signs of his officemate working on the project: "oh you've got to be kidding me," "why would they do that," "what the --?!"

One particular outburst, filled with plenty of not-safe-for-work language, caught Hannes' attention. It was on one of the hundreds of ASP pages that his coworker was trying to reverse engineer and document...


Comments from a Madman

by in CodeSOD on

It's hard to maintain your cool while writing software, and therefore hard to not have that reflected in comments. It's probably a good idea to get in the habit of searching the codebase and replacing four letter words prior to checkin.

Submitted anonymously, we were given a series of comments that chronicle one man's gradual descent into insanity. I've taken the liberty of removing calls to It.Basket.Add(theLotion).


A Plea from the Heart

by in CodeSOD on

Donniel Thomas writes "Javascript isn't for the weak of heart or those short of patience. What works in one browser may not function properly, or result in a nasty JS error in another (*cough*IE*cough). Which is why I can understand what this programmer meant."

The following screenshot is from the homepage of Zillow.com, which is one of the most popular and AJAX-y Real-Estate sites on the web. And, as of this writing, the coder's plea still remains ...


Code Reuse

by in CodeSOD on

Good developers know that, (1) Exception Handling is costly and might use thousands of CPU cycles to process which, in turn could take several nanoseconds, and (2) Code Reuse is important, and definitely faster to reuse the same block of code than to have two similar blocks.

Gooder developers (such as Abraham's colleague) not only know these facts, but know how to apply them simultaneously to maximize Speed and Code Reuse…


Odd or Even... or Both?

by in CodeSOD on

Part of the fun in Waldo W.'s job is working with third-party data providers and figuring out how to integrate the data into his company's applications. One of Waldo's favorite data providers is a Certain Address Data Service.

The address data provided by the vendor is partitioned into Odd and Even ranges for a given street. Sometimes -- usually when there are not a whole lot of addresses on a street -- the vendor puts them in the Both range. And this resulted in the following code being written to determine the evenness, oddness or bothness of the address entered...


It's Like Calling Assert

by in CodeSOD on

When we go from language to language and platform to platform, a whole lot of “little things” change about how we write code: typing, syntax, error handling, etc. Good developers try to adapt to a new language by reading the documentation, asking experienced colleagues, and trying to follow best practices. “Certain Developers,” however, try to make the language adapt to their way of doing things.

Adrien Kunysz discovered this following code written by a “Certain Developer” who wasn’t a fan of the try...catch…finally approach called for in .NET Java development and exception handling.


My Kind of Random

by in CodeSOD on

Taking over the maintenance of a web application can be a bit scary. Depending on its age and size, there's a good chance that it lives in a developmestuction environment, has no known documentation, and was built with an amalgamation of technology ranging from custom C++ CGI engines to the latest and "greatest" AJAX toolkit.

Fortunately, the web application that Chady was inheriting looked like it was in pretty decent shape. A quick sign on to the administration section revealed that each page request seemed to have its own 256-byte security key attached to the query string – impressive! Well, that is until he dug into the code.