"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."
bool memberHasFingerprint = bool.Parse(bool.FalseString);
"I recently inherited a project from a former co-worker who left our company because he decided he would rather live the life of a dishwasher," writes Marcela, "not that there's anything wrong with that, of course. The codebase is riddled with WTFs (variables named "please" and "whoa3"), but this one takes the cake:"
for (var i:int = 0; i < 100; i++){ var rand:int = Math.random() * 6; } SoundHandler.playExternalSounds(["positive_override" + rand]);
Mark writes, "advice that is true for life as well as code."
# The colon is very important. DO NOT TOUCH.
"This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())
"
public static bool IsRealString(object s) { return s != null && !String.IsNullOrEmpty(s.ToString()); }
"I'm all for moving chunks of code into descriptive methods for readability," Jeff S writes, "but this is a bit much... especially given that the original coder duplicated this method (with different names and types) in many places."
private IAlertDocument CompareObjectAsIAlertDocumentOrNullIfNotCastable(object compareObject) { return compareObject as IAlertDocument; }
Aaron found this comment burried in the code. He's thankful he's only a 3-month contract.
/* * See, this is why I hate my job. We start out doing some magical end-all solution for a may be customer, the * "XML Engine" hazily devised by IT iliterate decision makers without a clue what it's should do or who wants it. Ignore * that the codebase as is needs refactoring and fixing, let's ignore that we have a todo list a mile long, let's make * up requirements on top of that! Then, when reality kicks in and the may be customer isn't, we have semi-finished * shit clogging up all code arteries with poison. But noooo, don't clean it up, let's hack something else together * like this cover control thing, sort of based on what would have been the "XML Engine" (TM) with no clear requirements. * Then, let's not do anything about it for a year, and when another customer wants something similar, let's make * someone else program something from scratch, and hey, could we also make sure not to have this programmer coordinate * with the other programmer? Just to make sure that we don't do anything right? And, when the time comes that a third * client wants something in-between what these two programmers were forced to crap out, could we ask them to hack * something different together real quick to make absolutely sure that we're living on a pile of code shit, and also * top it off by "agreeing" to do that on a meeting that's supposedly "Scrum" planning, except we skip each and every * bit that would actually make it scrum and instead have the überboss jot in "agreements" and "deadlines" in an Excel * sheet? * * Sure thing, that's how we roll, baby! Let's do the third thing, unless custId is 1521. DB is in another script * altogether, so we don't need to worry about that. */
"Sure, it is sometimes difficult to come up with informative names for variables," writes LJ, "but our Russian subcontractor easily takes the grand prize in names that make no sense at all."
if (oneHundred == 100) { oneHundred /= 2; }
"The comment says it all," writes Mathew.
Private Function FnPtrToLong(ByVal lngFnPtr As Integer) As Integer ' Given a function pointer as a Long, return a Long. ' Sure looks like this function isn't doing anything, ' and in reality, it's not. FnPtrToLong = lngFnPtr End Function
"Even if you don't know PHP," writes Jacob Mather, "there's only one reaction this code leaves you with!"
<?php include dirname(__FILE__).'/../../../otherdomain.com/public_html/file.php'; ?>