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.

Nov 2014

Classic WTF - Yes, The Table is Still There

by in CodeSOD on

Our Discourse forum has received a mixed approval rating. Many folks like it, but others still find it lacking in areas in certain clients. Well, no matter your opinion, I can guarantee that, as it was true when the article first ran, our forum doesn't have the same problem mentioned below.


"Having recently upgraded my forum software," Kinta wrote, "I noticed that my site had been running incredibly slow."


Genderize

by in CodeSOD on

If someone suggested that you write a function which, given a person’s name, tells you what gender they are, you might caution that this is a hard problem. You might suggest a solution like a Bayesian classifier, which could be trained, or you might say, “Maybe we should just let the users tell us.”

There are a few things you almost certainly wouldn’t suggest. You wouldn’t suggest using ColdFusion , because CF is constructed out of sin and unicorn tears. And you certainly wouldn’t suggest trying to use regexes to do this job.


An Interesting Way to Find Even

by in CodeSOD on

While combing the server logs for clues as to what might have caused the latest incident in staging, Steve was startled to find that the box he was looking at hadn't logged anything for months.

Was logging disabled? No, it all looked fine. He accessed the box directly and the site came right up, complete with an entry in the access logs. So where were the logs for the past three months?


WTF from A to Z

by in CodeSOD on

Alex's customers were having issues with a web project management console developed by a coworker. Upon opening the code to see what was causing all the JavaScript errors, he learned that the original developer was clearly an expert in web development standards. The code file itself was JavaScript. The use of the .css() function definitely proved his mastery of Cascading Style Sheets. Hard-coded tags demonstrated his deep knowledge of HTML. Finally, his variable naming scheme is essential to maintaining the coveted "Now I Know My ABC's" certification.

var i = "DivContainer";
var j = "DEFAULT";
var k = "DEFAULT";
var l = a(document.createElement("select")).css("min-width", "200px").append(a(document.createElement("option")).val(""));
var m = a(document.createElement("select")).css("min-width", "200px").append(a(document.createElement("option")).val(""));
var n = a(document.createElement("select")).css("min-width", "200px").append(a(document.createElement("option")).val(""));
var o = a(document.createElement("input")).attr("name", "group1").attr("id", "RessRadio").attr("type", "radio");
var p = a(document.createElement("input")).css("width", "250px").attr("type", "text");
var q = a(document.createElement("input")).attr("id", "HiddenRessID").attr("type", "hidden");
var r = a(document.createElement("input")).attr("name", "group1").attr("type", "radio");
var s = a(document.createElement("input")).css("width", "250px").attr("type", "text");
var t = a(document.createElement("input")).attr("type", "hidden");
var u = a(document.createElement("a")).addClass("JButton").text("Display");
var v = a(document.createElement("label")).css("color", "Red");
var w = a(document.createElement("label")).text(" Display all employees assigned to a project: ");
var x = a(document.createElement("label")).text(" Display all projects assigned to an employee: ");
var y = a(a(this)[0]);

y.append("");
f = a(document.createElement("div"));
f.css("border-top", "1px solid Gray").css("width", "450px").css("padding", "5px");
f.append(a(document.createElement("table")).append(a(document.createElement("tr")).append(a("").append(a("").text("President:"))).append(a("").append(l))).append(a(document.createElement("tr")).append(a("").append(a("").text("Vice-president:"))).append(a("").append(m))).append(a(document.createElement("tr")).append(a("").append(a("").text("Head office:"))).append(a("").append(n))));
y.append(f);
y.append(a(document.createElement("br")));
y.append(u);

Committed to Committing Commissions

by in CodeSOD on

Simon worked in a small shop that supported a sales system. One of the features of the system was that sales commissions were stored in the database. For the sake of simplicity, the sales commissions were stored as the multiplier factor needed to compute the total sale. For example, a 5% commission on $100 would be $5, so the factor would be 1.05 so you could just multiply: 100 * 1.05 -> 105.

Of course, when they needed a report that showed the percent commission for a given sale, they had to work backward from the multiplier to get the actual value.


Exceptionally Secure

by in CodeSOD on

Error handling is not an easy task. Even the tiniest bit of code can fail in spectacular ways.

Luckily, modern programming languages tend to use at least some sort of exception model, which means that even if your program crashes, you’ll still be able to obtain more debugging information than a "Segmentation fault" or other generic error message would provide.


A Binary Number Generator

by in CodeSOD on

Rich had heard countless complaints from Cindy in Finances that the reports were "slow".

Mostly though, he'd blown them off -- anything shy of instant was "slow" to her, and there wasn't a lot of room to go wrong in an SSRS package. Still, she was pretty, so he decided to take a look. Maybe he could speed up the reports and earn her gratitude. How bad could it be?


The UntouchaDBles

by in CodeSOD on

Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio continues his job as the sole developer of software managing hundreds of residents.

It's always a bonus when the same brave soul delivers multiple WTFs for our exasperation. Our very own man from La Mancha has been doing a lot of refactoring lately, retaining the GUI of his employer's Assistance-Management System while replacing the zany consultantware underneath with vastly improved code.


Brick by Brick

by in CodeSOD on

Jannik worked for a company known for a line of building products . They were an international company, which meant they had to make sure their website supported multiple languages. They embedded this information into the URL, eg http://company.com/eng/orders.

They tracked the list of valid languages in an array: