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.

Jun 2017

Plurals Dones Rights

by in CodeSOD on

Today, submitter Adam shows us how thoughtless language assumptions made by programmers are also hilarious language assumptions:


A Lazy Cat

by in CodeSOD on

The innermost circle of Hell, as we all know, is trying to resolve printer driver issues for all eternity. Ben doesn’t work with the printers that we mere mortals deal with on a regular basis, though. He runs a printing press, three stories of spinning steel and plates and ink and rolls of paper that could crush a man.

Like most things, the press runs Linux- a highly customized, modified version of Linux. It’s a system that needs to be carefully configured, as “disaster recovery” has a slightly different meaning on this kind of heavy equipment. The documentation, while thorough and mostly clear, was obviously prepared by someone who speaks English as a second language. Thus, Ben wanted to check the shell scripts to better understand what they did.


Classic WTF: Hacker Proof Booleans

by in CodeSOD on
We continue our summer break with a classic case of outsmarting oneself in the stupidest way. Original -- Remy

"Years ago, long before I'd actually started programming, I spent my time learning about computers and data concepts by messing around with, believe it or not, cheat devices for video games," wrote Rena K., "The one I used primarily provided a RAM editor and some other tools which allowed me to tool around with the internal game files and I even get into muddling around with the game data all in the interest of seeing what would happen."

"As such, by the time my inflated hacker ego and I got into programming professionally, I was already pretty familiar with basic things like data types and binary. I was feeling pretty darn L33T."


Classic WTF: It's Like Calling Assert

by in CodeSOD on
We continue our summer vacation with this gem- a unique way to interact with structured exception handling, to be sure. Original. --Remy

When we go from language to language and platform to platform, a whole lot of “little things” change about how we write code: typing, syntax, error handling, etc. Good developers try to adapt to a new language by reading the documentation, asking experienced colleagues, and trying to follow best practices. “Certain Developers,” however, try to make the language adapt to their way of doing things.

Adrien Kunysz discovered this following code written by a “Certain Developer” who wasn’t a fan of the try...catch…finally approach called for in .NET Java development and exception handling.


A Promise of Timing

by in CodeSOD on

Asynchronous programming is hard, and there’s never been a perfect way to solve that problem. One of the most widely used solutions is the “promise” or “future”. We wrap the asynchronous process up in a, well, promise of a future result. “Someday, there will be data here, I hope.” The real beauty of promises comes from their composability- “getData promises to fetch some records, and then the calling method can promise to display them.”

Of course, it’s still asynchronous, and when an application has multiple asynchronous processes happening at the same time, “weird behavior” can happen, thanks to timing issues. Keith W encountered one of those timing related Heisenbugs, and became immediately suspicious about how it was getting invoked:


Variation on a Theme

by in CodeSOD on

If you’re not already aware, the Daily WTF is open source. We went the route of building our own CMS mostly because our application needs are pretty light. We don’t need themes, we don’t need WYSIWYG editors, we don’t need asset uploads. Also, with home-grown code, we know what’s in it, what it does, and any problems in the code are our own.

Which brings us to WordPress, land of the themes. There’s a cottage industry around building WordPress themes, and it’s a busy enough space that there are specialists in developing themes for specific industries. Alessandro ended up doing some work in the real estate business, tweaking a WP theme to change the way certain images would get displayed in a slide show.


Switched Over

by in CodeSOD on

Twelve years ago, a company decided they needed a website. They didn’t have any web developers, and they didn’t want to hire any, so they threw a PHP manual at the new hire who happened to “be good with computers”, and called it a day.

Ms. “Good With Computers” actually learned something from the experience, and moved on to a lucrative career in web development. Unfortunately, she left behind the code she learned by doing, and now Bert has been brought in to clean up the code.