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.

Dec 2014

Classic WTF - The Fizz Buzz from Outer Space

by in CodeSOD on

To close things out for 2014, we're re-running our most popular articles. Without further ado, enjoy one of our most popular; this one originally ran in September.


Matteo recently interviewed a candidate that was employed elsewhere as an “architect”. His responses to the standard soft-skills questions sounded a bit rehearsed, which made Matteo suspicious, so he started asking some more technical questions, like: “What’s the difference between an interface and an abstract class?”


Hashing the Ruby Way

by in CodeSOD on

Ruby praises itself as the language that “makes programmers happy”. It does its best to be expressive and encourage a declarative style of programming.

Oxygen480-actions-irc-close-channel


A Perfect 10

by in CodeSOD on

two-hands-equals-10-fingersAndrew found this code on the product pages of a fairly popular automotive e-commerce website. It's called whenever an 'attribute' of a product (size, color, etc.) is selected or changed by the user.

The main focus of this code is to update a concatenation of the values of all currently selected attributes which are stored in a hidden form input field. Once it has done that, it hands off to another function to make an AJAX request with this concatenated value as a parameter.


JSON at Crystal Lake

by in CodeSOD on

Trevor found an unusual bug. Every customer had a GUID, but for some reason, their JSON API failed if there were ever more that 75 results.

He checked the web layer, only to find that it didn’t actually build the JSON- it just returned a string. The string itself came from their Oracle database. That’s where this procedure came from:


Polynomial Optimization

by in CodeSOD on

Marlschlag falsch&Schlingen

Rayer S’s co-worker exploded into his cube, beaming. “I’ve just optimized our processing loop. I’ve gone from O(n2) to O(n)!”


You Can't Fire Us Until We Quit

by in CodeSOD on

When one of Felix G’s newest design customers decided that they were officially unhappy with their current web-agency, another company's loss was his gain.

His first assignment was a simple one - remove the code that displayed the website’s creator credits (something like 'developed by xyz') from an external website.


Is Something Happening Right Now?

by in CodeSOD on

Most programmers are familiar with a notion of technical debt. Sometimes all it takes to make or break a project is a single bad decision, questionable design solution, or even a plain old bug that doesn't get fixed early on. The hacks and workarounds keep piling up, slowly turning the project into an unmaintainable mess.

In this regard, David was already off to a head start. He has recently been assigned to maintain a meeting tracking system with – to put it lightly - a bit of history. A year before, the marketing department of his company received the first version from a subcontractor and promptly implemented it – only to find out that the data gathered were a little off. According to the reports, every single meeting lasted exactly 24 hours – from midnight to midnight.


Will Managers Never Learn?

by in CodeSOD on

Arty works on a team maintaining a legacy application that can best be described as a birds nest of code. It is a massive collection of global variables and a few tens of thousands of routines that would independently modify the data. Decapsulation was the overriding design pattern of choice. Of course, changing the value of some variable invariably has all sorts of unpredictable side affects. Naturally, this lead management to be fearful of making any changes, no matter how urgent, for fear of what would inevitably happen.

Fortunately, management recognized the need to replace it. The directive was given. A new application would be built. The replacement would be designed in such a way as to keep data and the routines that needed to access it somehow tied together. The state of a variable would only be changed as an end-result of some business action.