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.

24 Nov 2014

An Interesting Way to Find Even

by Jane Bailey in CodeSOD on 2014-11-24

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?

7 Comments - Last Comment @ 13:06
19 Nov 2014

WTF from A to Z

by TJ Mott in CodeSOD on 2014-11-19

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]);

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))));

35 Comments - Last Comment @ 2014-11-20
17 Nov 2014

Committed to Committing Commissions

by snoofle in CodeSOD on 2014-11-17

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.

76 Comments - Last Comment @ 2014-11-22
12 Nov 2014

Exceptionally Secure

by Maciej Stachowski in CodeSOD on 2014-11-12

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.

63 Comments - Last Comment @ 2014-11-23
10 Nov 2014

A Binary Number Generator

by Jane Bailey in CodeSOD on 2014-11-10

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?

64 Comments - Last Comment @ 2014-11-14
05 Nov 2014

The UntouchaDBles

by Dan J. in CodeSOD on 2014-11-05

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.

50 Comments - Last Comment @ 2014-11-07
03 Nov 2014

Brick by Brick

by Remy Porter in CodeSOD on 2014-11-03

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

They tracked the list of valid languages in an array:

77 Comments - Last Comment @ 2014-11-12