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 2007

Converting Apples to Oranges

by in CodeSOD on

In high school I'd spend most of my time in math class playing with my calculator. It had all sorts of fancy conversion functions that were mostly accurate, and simplified work that I'd rather not do myself. One undocumented (and fun) feature was that the conversion functions weren't limited in scope, meaning that I could, for example, convert hours to milliliters or inches to degrees celcius.

I imagine that the culprit behind today's CodeSOD submission from Tony I. had the same calculator. The reason I've taken a picture is that Tony physically mailed the submission to the WTF world headquarters.


Classic WTF: calculatethenumbers(v,w,x,y,z)

by in CodeSOD on

Happy Memorial Day, U.S. readers! And for you non-U.S. readers, Happy .. errr ... Regular Day of the Week! calculatethenumbers(v,w,x,y,z) was originally published way back on July 21 in 2004 ...


Ray Suker sends in a function from a system he inherited from the Guru who designed it before him:


Early Termination

by in CodeSOD on

Once, I asked a coworker for a feature request. His service was outputting hashes and I wanted the original strings. His reply was that if I had an algorithm to reverse a hash --- all that this service stored and obviously impossible --- he'd implement my feature. My suggestion was that he record an input-to-hash mapping and just reverse that. The feature was checked in that day; perspective makes all the difference. My next feature request was that he set up a signal handler to catch signal nine, as he had attached cleanup routines to several other signals. I guess he spent the rest of the day trying to figure out why it wasn't working.


And I guess that's the point: for many things there is an obvious solution, for some things there is no solution, and wisdom is knowing the difference. The problem is second-guessing things that cannot occur, especially when you guess wrong. One of our field agents, Paul, recently had a run in with murderous #9; he writes,

'We once bought some code from a large company who shall remain nameless. Security was the big issue, so a programmer came up with the not-so-bright idea of how to be sure that a small utility program would really exit and not somehow keep running.

An Amusing Way of Saying UPDATE

by in CodeSOD on

Four months ago, Kevin P. joined a well-known health care provider as a project lead. Little did he know what he would find himself leading.

After a complete overhaul of the architecture (or what passed for an architecture), K.P. still deals with little nuggets of joy like this every day...


The Dimmer

by in CodeSOD on

When Ben started working at a small ASP-based dotcom, there was an intern who was working on a major feature of their application. Her code confusingly cute. Quick example: instead of calling a database table for checklist templates "CLTemplate" and having one row per checklist, she called it "CLManager" and had columns CLItem01 through CLItem100.

Okay, maybe that's a bit obnoxious. But consider her sub for "dimming" (i.e. declaring variables in VBScript) ...


Seeking the Truth

by in CodeSOD on

We're all seeking truth and elightenment. Some find it in Christ, some in Allah, some in Shiva, crazy celebrities in Xenu, fat goth weirdos in Satan, or the truly enlightened who've been touched by the Flying Spaghetti Monster's Noodly Appendage. Others find it in science. Maybe even in love. Well, for those of you that haven't found the truth yet, here it is:

private static bool GetTrue() 
{
   return true; 
}

Classics Week: Removing Spaces, the Easy Way

by in CodeSOD on

Removing Spaces, the Easy Way was originally published on February 22, 2007.


There are tons of functions in so-called "standard" libraries, but sometimes the function you want just isn't there. Luckily, string functions are so simple to write that anyone can do it!


Classics Week: Laying the Foundation for i18n, Brick by Brick

by in CodeSOD on

Laying the Foundation for i18n, Brick by Brick was originally published on February 07, 2007.


In Europe, they do things a little bit differently. From what I understand, it boils down to this: they work less and play more; when not working or playing, they drive tiny little cars. Apparently, they all speak different languages too.


Classics Week: But It Worked in the Demo

by in CodeSOD on

But It Worked in the Demo was originally published on January 26, 2007.


We've all been there: all of your test cases worked the night before but when it comes time to run the demo you realize you missed something. In college, I had to write Sub Hunter in assembly and those pesky submarines kept launching missiles after I depth charged them back to hell. The TA didn't notice either. It wasn't until later that I learned about the magic of peer review. Not that fewer bugs sneak across the unit test border, you just feel better because someone else missed the problem too.


Classics Week: How Not to Parse Command Line Arguments

by in CodeSOD on

How Not to Parse Command Line Arguments was originally published on December 15, 2006.


Today's Code Snippet is from S.C., who shared this in the Side Bar a littler earlier this week ...


Classics Week: The Mentor

by in CodeSOD on

Today's Classic WTF was originally published on Wednesday, November 08, 2006. An interesting fact: this is actually the same Chris and the same Mentor from an earlier article, Mentors, the Freshmaker.  


Today's Code Snippet comes from Chris. Chris has had the distinct pleasure of being "mentored" by an amazing individual. Some time passed, then Chris bumped into The Mentor again. This time Chris had to rework a web site The Mentor had, dare I say, created? As Chris was going through the code for the page design, he noticed something curious about the footer. No matter where the page was scrolled to, the footer always showed up. "Very nice", he thought to himself, "I wonder where he got the script?" Turns out The Mentor had written it himself.


Splitting Headache

by in CodeSOD on

When it comes to string manipulation, it is not uncommon to want to split a single string into multiple strings based on a delimiter. Many languages provide split functionality outright. Even in C, it's fairly easy to roll your own --- assuming you don't like strtok_r --- with functions like strchr or strpbrk.

Jake says that, in Java, this was not the case until 1.4, which is the same thing the documentation says. Apparently one of the developers with whom he works still does not realize this. The following function was developed recently and is still being used in new code.


Buzz, Cell Phone, Buzz

by in CodeSOD on

Mobile communications is a complicated but lucrative business. With all the buzz surrounding (and created by) cell phones, that's not surprising. And they're not just for calls any more! The new big thing is interacting with web pages and other applications via SMS.


What's SMS? Who knows, but it's an acronym so that means it's probably great. At least that's what Jared's company thought, which is probably why they were in a mad scramble to interface their web service with every cellphone on every network, ever. The problem? No one knew anything about how SMS worked.



Double Take

by in CodeSOD on

This is the story of two Daves. At first, they may appear to be from completely different worlds. One does client-side web development, one server-side web services. On further reflection, however, they have quite a bit in common.


For one, they both ended up together in this article. That sounds like a match made! With that in mind, Alpha Dave has something on his chest. Also, he needs to get it off.



Deterministic Programming

by in CodeSOD on

There is a lot of uncertainty in the life of every developer. How will this section of code interact with that section? What if the network goes down? What if a gamma ray flips that bit? What's mom making for dinner? Does radon have a smell?


In fact, a large part of computer science is the study of how to eliminate uncertainty. At the top, there are formalisms like the pi-calculus and abstractions like CSP. Sometimes simple state diagrams can be a godsend. And even if you've never seen any of those, there is still room to do your part.