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 2016

Scrubbed Inputs

by in CodeSOD on

In this age of JavaScript everywhere, developers have to come up with all sorts of ways to work around the uglier segments of JavaScript. For example, Aaron found this block, which promises to scrub “false-y” fields.

require _ = require("underscore");

// recurses, use with care
var scrubFalseyFields = function (obj) {
    return  _.chain(obj)
        .pairs()
        .filter(function (pair) {
            var val = pair[1];
            if (_.isObject(pair[1])) {
                // recurse!
                pair[1] = scrubFalseyFields(val);
            }
            return val;
        })
        .object()
        .value();
};

The Last of His Tribe

by in CodeSOD on

"The best thing about working here," Jaeson was told by his boss Renee on the walkthrough of the dev area on his first day, "is that we work closely with the customers, meaning you never EVER have to cash checks the salespeople wrote: you're only held to what your team promised." This sounded good to Jaeson, who was considerably more concerned about getting away from his previous company's open floor plan than the possibility of customer interaction, but hey, he'd take the icing on the cake. It sounded like he was in for a very productive time.

"Let's see, where to put you," mused Renee, glancing over the pods of cubicles. "Aha, I think Zebra Tribe will work." Zebra Tribe, it turned out, was the name of a scrum team; Jaeson would be working closely with the other members of that tribe, as they were called, in the coming months in order to accomplish tasks during sprints.


You Can't Always Count on Regular Expressions

by in CodeSOD on

After spending the most of the afternoon searching, trying to solve a rather vexing issue, Adam found exactly the solution he was looking for and wanted to squirrel it away for later reference.

Sure - he could have added to "Favorites" in his browser like on every other website in the world, but there was something about the "bookmark" button on this particular site that called to him. It was more than a dumb link, it was a counter telling you how many people had bookmarked a resource, and you could bookmark it yourself.


Finding the File

by in CodeSOD on

There’s one challenge we rarely think about when writing file-handling code: how do we know where the file actually is? Josh H. inherited some C# code that puts a lot of thought into that. A lot.


            

String Cheese

by in CodeSOD on

Imagine you’re a Java programmer. You need to iterate across a list of strings. Your natural instinct might be to just use a for loop, and that’s proof that you’re not a true enterprise Java programmer.

Diether’s company is home to true enterprise developers, and they know how to get things done.


Code Changes Over Time

by in CodeSOD on

Code changes over time. Most of what developers do is manage changes to code. Dana inherited some pretty awful PHP, and decided to take some time to improve performance and make sure any errors thrown by the PHP were actually displayed nicely for the user.

While looking at the file-upload module, Dana found this:


The Self Test

by in CodeSOD on

I consider code cleanup to be important, almost as important as actually writing code, especially since I spend a lot of time doing maintenance and support. During idle time, I enjoy digging through existing code to find overcomplicated algorithms and dead code and see what I can simplify or even delete. While there may not be an immediate benefit, it makes future debugging far easier if you trim out dead code and shorten 3,000 line C files to 500 line ones. And quite often, subtle and difficult-to-diagnose bugs simply go away.

While doing this on one of our products, I found a very old public API that appears to have never been completed. At least I hope so, because there’s no way any of it does anything remotely useful.


JavaScript Obfuscation

by in CodeSOD on

We have to be careful about the articles we publish on TDWTF. We have a responsibility to our submitters, to protect their identity and anonymize the details of their stories. We have a responsibility to our readers- mostly to be entertaining.

Last week’s JSF–k story failed one of our readers. Poor Blazej didn’t find it entertaining- it gave him upsetting flashbacks to his own experience with a similar event.


Widgety Gadgety Boo

by in CodeSOD on

“The road of life twists and turns and no two directions are ever the same. Yet our lessons come from the journey, not the destination.” - Don Williams, Jr. (4719290483)

Ancient Coder submits for our review the following migraine-inducer:

This was a bug report about a very minor issue, a little warning box was not popping up. Simple, I thought, and I estimated it would take an hour to fix. Little did I know that someone had already poked at this issue and made this amazing log entry. I spent about half an hour trying to understand this code before I backed away, slowly.

The Monthly Report

by in CodeSOD on

Karen, you need to run the monthly report while Ivan is on vacation,” Bruno asked.

“Wait, isn’t that just a scheduled job?”