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.

Mar 2011

No Letters Allowed!

by in CodeSOD on

"The data validation requirements for a telephone number are dead simple," writes Chris M., "Just the numbers and that's it. The user can enter their numbers with dashes, brackets, parens, whatever.  Only the numbers should be saved."

"You would think that filtering out the non-numeric characters should be a simple thing to do with regluar expressions or heck, even walking the string would be feasible."


Gary Strikes Again

by in CodeSOD on

Back in January, Gary taught us a lot during his tenure with Initech.

Whenever Jake would offer him an idea on how to get something done in his ASP.NET project, Gary would say that it could not be done for one or more of a list of stock reasons: “security issues”, “incompatibility with ASP.NET”, “.NET doesn’t have that feature”, et cetera. One wonders which of these motivations produced the following code for copying the business database customer table to the database that backs the web presence.


TAG++

by in CodeSOD on

C++ has a consistent and fairly simple syntax for defining classes and class members. While this syntax would still look like gibberish to a non-programmer, an entry-level coder could probably understand it after flipping through C++ for Dummies. Kevin Day's predecessor must have been concerned that the former group might be maintaining the system.

Fast forward a few years, and management, not surprisingly, decided that the best folks to maintain their C++ codebase would be, in fact, C++ programmers. And that's where David came in. Faced with the common dilemma understanding a foreign architecture of a foreign product in a foreign business domain, David had at least one bit one thing going for him: a good working knowledge of C++. But since the original designers decided to #define a meta-language in C++, and then use that meta-language to represent all of the key classes, his knowledge hardly came in handy.


A Spoonful of Sugar

by in CodeSOD on

John S. was doing some work on the search feature of a client's website when he noticed that he would receive a 500 Server Error if he tested against the API with an empty string.

This struck John as being pretty strange since not only had the search feature had been in place for years, but also, he could go to the search page, click on the "Search" button without entering anything and receive an "Item Not Found" response.


Logging the Logger

by in CodeSOD on

"My team has recently inherited a massive monster of a Java J2EE based system," writes Terence White, "some of the code leaves me to wonder if the reason these guys had no peer review was that they had no peers."

"One thing they were obsessed with was logging. And logging their logging. It's no wonder why the system required a handful of servers for a few dozen users..."