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 2011

Random Char and Triply-Random Double

by in CodeSOD on

"As a student, I don't really feel qualified to what good and bad code is" writes Dan, "at least, that's how I felt before landing my first internship."

"When I asked my 'mentor' why he didn't just use the Asc function (which I found after a few-second search) to convert a random number to a random character, he responded that this seemed cleaner."


The Andy Pattern

by in CodeSOD on

Although Andy had left for greener pastures generations ago, everyone on Julius's team knows Andy. Actually, it's hard not to know him.

It's not that Andy's code is that bad. It's certainly buggy and rarely works properly, but that alone doesn't make it memorable. It's more... the Andy in the code. Take, for example, this snippet of code from RFIDAndyJulRequest3.pde:


The Über Logger

by in CodeSOD on

The idea was sound: make a generic logger that could log anything and everything, anywhere and everywhere, anyhow and everyhow. Granted, there were already several open-source, commercial, and built-in logging options that basically did that already, but the Über Logger would sit at a level above all of these loggers and thus could log to another logger... or even all of the other loggers. At least, that was the theory.

In practice, the Über Logger turned out to be a little more... messy. "Basically," wrote Floyd, "this method is, naturally, copied-and-pasted on all of some 200+ ASPX files where logging is needed."


The Anti-SQL Coalition

by in CodeSOD on

"There is a small coalition of developers at the office who are vehemently anti-database," writes Bob, "naturally, this faction also doesn't value 'experience' -- mostly, because they have none. At least, not outside their university studies. They'll often liken a database server to a file system, and suggest that it's just a convenient way to store blobs of data -- but everything else is inelegant bloat."

"Of course, since this coalition doesn't have any actual decision making power, their strong opinions remain just that, and we stick with a standard tech of technology. Of course, their attitude often leaks into the code, as in this example of a simple search query that was used to search for an employee by name. The trick is we have employees with accented characters in our directory but, if a user search for the name without the accented char (e instead of é), it needs to return the result anyway."


Serious String Validation

by in CodeSOD on

"I've been given the task to port some old code to a new platform," writes João Neves. "While porting some Javascript string validation functions, something caught my eye. "

"Now my eyes are filled with tears."


Bad News Enum

by in CodeSOD on

"Enums are bad news," Diego's boss would often say, "they don't add any real value to the code, and they're that much more 'bloat' from Java. I've been coding in C for 20 years, and did just fine without them."

Despite being the senior Java architect, Diego's boss had deep-rooted distaste for Java. Diego didn't really understand why there was such a hatred against Enums specifically, until he stumbled across some of the architect's code.


Truth Enough

by in CodeSOD on

"I recently started on a contact that would make for a great Daily WTF story on its own," writes Kyle Y, "there's paranoid management, highly restricted internet access, no outside email... it's the works!"

" If I manage to stay for more than a couple weeks, I'll be sure to follow-up with a full report. But in the meantime, I wanted to share some code. I took a 'screenshot' of a representative snippet... though I suppose I should have printed it out first and snapped it on a wooden table."


The True Alternative

by in CodeSOD on

"I inherited a system that that has it's own special ways of doing things," writes Brenden Sharp. "There are lots of things in there warrant facepalms, but few things are at the level of The Daily WTF submissions. Well that, and I've just gotten so used to it that it doesn't faze me anymore."

"But recently, when I was tracking down a bug, found this very special code."