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.

Jul 2015

You've Got My Number

by in CodeSOD on

Luftballons Hannover

Today's snippet needs very little introduction. In the words of the submitter:

[My predecessor] is what I would consider, among the worst programmers in the world. While his programs actually do work and do what they should, his techniques and programming decisions are very questionable. The [below] code snippet is from a program he wrote after he spend about a year at this company.

Patterned After Success

by in CodeSOD on

Design patterns are more than just useless interview questions that waste everyone’s time and annoy developers. They’re also a set of approaches to solving common software problems, while at the same time, being a great way to introduce new problems, but enough about Spring.

For those of us that really want global variables back in our object oriented languages, the Singleton pattern is our go-to approach. Since it’s the easiest design pattern to understand and implement, those new to design patterns tend to throw it in everywhere, whether or not it fits.


The New Zero

by in CodeSOD on

If Alice needed to rate her co-workers, on a scale of 1–10, whoever wrote this is a zero. The goal here is to create a new string that is 4096 characters long and contains only zeros. This was the best approach Alice’s co-worker found:

string s = new String("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

Pointerrific

by in CodeSOD on

Rusted chain

Working with a legacy codebase is like embarking on an archaeological expedition to a foreign land: you never know what ancient artifacts you're going to uncover. Will it be the mighty fast inverse square root? The rusty yet still operational Duff's device? An old COBOL module forgotten by time, quietly holding the universe together?


Classic WTF: XML Abuse

by in CodeSOD on

Is it still trendy to hate on XML? Of course it is! But this WTF would still be a WTF if it were built in JSON, because this is terrible.

This classic comes from 2008, but finding WTFs in XML knows no decade. - Remy

"Where I work we keep a lot of data stored in XML files," Ben writes. "They're not your average XML files, though — they're special." His colleague invented the following technique (recommended for senior level XML programmers only).


Mistakes Were Made

by in CodeSOD on

As a general rule, “dead code” should never be commented out, but instead, should be replaced. If you ever need to review the history, source control contains that information.

But sometimes, the “I’ll just comment it out” lets us see the moment of realization, when a developer discovers that they’ve done the absolute wrong thing. Clara sends us this: