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.

Feb 2010

Rendered Pointless

by in CodeSOD on

"The mastermind behind our system is the Senior Developer," wrote Daniel, "he's naturally an expert at all things code, but he especially excelled at back-end systems. After all, true geniuses always value function over form."

"The Senior Developer liked to do things a little differently, but we got over his quirks. Take, for example, this handy dandy function to ease the pains of those complicated cast operations we all hate."


isValidNumber()

by in CodeSOD on

"When my company, a large financial corporation, decided to outsource overseas," Ned wrote, "they went for the best: CMMI Level 5. Not Level 3 or Level 4, but Level 5. 'Heck,' the CTO told us half-jokingly, 'the offshore team will make us look bad!'"

"It's hard to describe the 'high quality' code that gets checked-in to our repositories. 'Bloat' just isn't quite strong enough, nor is 'incredibly horrible mess that makes me want to smash everything in sight'. There were a lot of issues with the code, but this one is my best short examples: isValidNumber()."


Last, Last, Last, Last, Last, Last, Last Year

by in CodeSOD on

"At my previous job," John S writes, "we had a good amount of formality in the development process. Business 'customers' would define requirements (or bugs), business analysts would write requirements to implement those, and we would write code against the requirements."

"When I took a new job at a small company, I knew the processes wouldn't be a little more 'casual', but I never quite expected this. Even the code is written casually, avoiding unnecessary formalities like arrays and loops."


Probeility of Success

by in CodeSOD on

The Fearless Leader at Randy's company had heard wonderful things about Service-Oriented Architecture, and knew that's exactly what their in-house applications needed in order for the company to remain competitive. Obviously, in-house developers couldn't possibly have the skill or knowledge to develop such things, so the Fearless Leader brought in consultants to develop the service suite.

One of the web services that the consultants developed was the Global Customer Search. Essentially, it searched for customers through a handful of different systems throughout the entire enterprise. "According to the documentation," Randy wrote, "the GES uses an advanced scoring algorithms to determine how close of a match a record may be when someone searches using the web service. As you can see from the code, the consultants started off on the right foot... and then decided to give up at the end. "


Quite Contrary

by in CodeSOD on

Mike writes, "Oh, the things that I find in our codebase."

"I have no idea who put this in, or why it was put in. But it's there, and it's somehow called in a few places. As tempted as I was to investigate how it was used, I figured I'd spare my sanity."


Phishing for a Refund

by in CodeSOD on

As I'm sure is the case with many of you, I sure do love me some tax refund. Once my W2's and other year-end tax forms documents come in the mail, I get my e-File in and wait for my refund to be direct deposited.

Now, since the whole refund process involves computers and the internet, of course, it's a prime target for spammers and phishers who want nothing more than to ignite a little FUD and get some of your hard earned cash.


Almost Counting Past 100

by in CodeSOD on

"At the contract shop where I work," writes John S., "I have been assigned to a new web-enabled mapping program to help take a look at some of the issues they've been having."

"When an item is added to a map, it is given a label, such as Item #1, Item #2, etc., with the number on the label incrementing for each new item. We had been having a problem where map labels were not being assigned uniquely when there were more than 100 items per map. It was always starting at Item #100 when reloading the map from the database. This was causing issues since it was the map label name that was being used for the unique identifier (don't get me started on that). Curious, I took a look at the code to decipher how the label ids were being assigned."

setCount: function(label) {
        var layer;
        var count;
        if (label.charAt(label.length - 2) == ' ' ) {
                layer = label.substring(0, label.length - 2);
                count = label.substring(label.length -1) * 1;
        } else {
                layer = label.substring(0, label.length - 3);
                count = label.substring(label.length - 2) * 1;
        }
       
        if (this[layer] < count) {
                this[layer] = count ;
        }
}

Else... where?

by in CodeSOD on

"I had a professor once who said that given enough NAND gates, he could rule the world," writes Rob B. "This was a roundabout way of saying that, using a whole bunch of NAND gates, you could create the function of any other logic gate. You shouldn't, because the other logic gates exist and it would be hugely wasteful to use NAND gates to do the same thing, but it can be done. It turns out this applies to code as well."

"We got some utterly garbage C++ code from a subcontractor. The error-to-lines ratio was amazingly high, and there were a lot of things to hate about it (like having one global function to get bits from a binary value which didn't work, and several different localized one-off solutions which did work). My main WTF moment, however, was the following."