Some terrible code arises out of terrible business rules which no one truly understands. Some terrible code arises from laziness, sloppiness, or the need to just get it done now.
Comments are a vital part of making code readable, but they’re more than just documentation. They’re communication between one developer and another. They tell us what the code does, but also how we feel about it.
While wading through hundreds of disallowed implicit casts and such from turning option strict on for a large project, Tevildo came across this little gem.
When it comes to bad code, everybody thinks they’re a comedian. Heck, look at us! Stupid programmer jokes are a game everyone can play, though, so let’s enjoy an evening at the Improv with some code comedians.
A huge number of the bad code submitted to TDWTF is related to dates. This isn’t all that surprising- dates are very complex data structures with a vast number of possible representations and huge cultural variations.
"I guess the developer wanted to make make sure that all his bases were covered!" wrote Ryan.
"I've been trying to fix up the last project a colleague completed before heading for greener pastures," wrote Philip Tyre. "After finding this comment, I'm beginning to have bad thoughts about what I may find lurking around..."
"We're had been using a manufacturer's web service, but started getting errors all of a sudden," wrote Peter Lindgren. "Something has really, really failed."
"I recently found this while going over some code in a Util library used by my project," Ian writes, "clearly, this method makes sure the job gets done."
"I found a schizophrenic comment that either intentionally or unintentionally happens to be a haiku," wrote Ben Vanik, "svn blame says this single line is the work of 3 different people across 3 years of coding."
"We had a programmer in our company whose specialty was to write functions that embodied his own personal traits," Winston Muller, writes "do absolutely nothing and mislead everyone to think that something was done."
"Following the code-as-a-commodity principle," writes Jan, "our management team not only sends large projects overseas, but goes with the lowest bidder."
"I just inherited a PHP application and discovered this," writes David Green. "I don't know what's worse: the fact that it says add but is performing subtraction, or that I can't find the accompanying addnoise() function."
" "I found a function called 'Important-Function' in a colleague's PowerShell script," wrote B. Versteylen, "after expanding the function, I discovered this."
"I found this line of code while doing some cleanup," Adam Aldrich writes, "this has to be the worst way to set a boolean variable to false."
Seeing that I somehow neglected to publish an article yesterday, I figured today would be a great day for a big ole smorgasbord of interesting code. Enjoy!
"Everyone knows that Russians are the best programmers, and the guy we recently hired is no exception," Kip DeMane wrote, "though his English is a little... off. Here are his comments from a recent commit."
"This code was left by the Senior Software Consultant," Michael Wheeler writes, "I'm not sure if it's insurance against 'Return' not returning... or a comment that explained why the line of code was left in."
"Some programmers like to program defensively," wrote Sam, "and then there's some of my coworkers. This is found at the top of nearly every function of our C++ classes."
It's a particularly busy week for me: on top of a few looming deadlines, I'll be at Business of Software 2008 in Boston. So, I figured it'd be the perfect opportunity to revisit some classics.
For more fun-but-not-necessarily-bad code, check out the previous episode: Coded Smorgasboard: Muhahahahaha
It's time for a new series: The Coded Smorgasbord. Inspired by the Pop-up Potpourri, the examples presented here aren't necessarily "bad" code nor do they imply the miserable failure that we're all used to reading here. Like previous "bunch o' code" articles, the examples are more-or-less fun snippets of code like ones that we've all written at one time or another. Enjoy!
It's time once again to give all those cool-but-too-small-to-make-a-full-post submissions a home ...