Funny Programming Comments

Sometimes, you’ll be knee-deep in somebody else’s code, only to stumble across a comment that is so unexpected and/or hilarious that you makes you break out into laughter.

// I dedicate all this code, all my work, to my wife, Darlene, who will 
// have to support me and our three children and the dog once it gets 
// released into the public.

That just reeks of confidence, doesn’t it?

/**
* HERE THERE BE DRAGONS
**/

Which is just another way of saying that the following piece of code has some “quirks”.

//Connects to MySQL if its available.
//John - 03/09/09 - WTF, this function just connects 
//to see if it can connect before connecting.
function connectIfAvailable($host, $user, $pass){
    $canConnect = mysql_connect($host, $user, $pass);
    if($canConnect){
        mysql_close($canConnect);
        return mysql_connect($host, $user, $pass);
    } else{
        return false;
    }
}

I found the above example in an include file that connected to several different databases. I spent the next five minutes chuckling away to myself.

// I have no idea what I am doing.
public function clean_name($name){
    $name = str_replace(".", "", $name);
    $name = str_replace(",", "", $name);
    $name = str_replace("-", "", $name);
    $name = str_replace("(", "", $name);
    $name = str_replace(")", "", $name);
    return $name;
}

At least he’s honest.

long john; // silver
/*
 * You may think you know what the following code does.
 * But you dont. Trust me.
 * Fiddle with it, and youll spend many a sleepless
 * night cursing the moment you thought youd be clever
 * enough to "optimize" the code below.
 * Now close this file and go play with something else.
 */
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
// At this point, I'd like to take a moment to speak to you about the Adobe PSD
// format. PSD is not a good format. PSD is not even a bad format. Calling it
// such would be an insult to other bad formats, such as PCX or JPEG. No, PSD
// is an abysmal format. Having worked on this code for several weeks now, my
// hate for PSD has grown to a raging fire that burns with the fierce passion
// of a million suns.
//
// If there are two different ways of doing something, PSD will do both, in
// different places. It will then make up three more ways no sane human would
// think of, and do those too. PSD makes inconsistency an art form. Why, for
// instance, did it suddenly decide that *these* particular chunks should be
// aligned to four bytes, and that this alignement should *not* be included in
// the size? Other chunks in other places are either unaligned, or aligned with
// the alignment included in the size. Here, though, it is not included. Either
// one of these three behaviours would be fine. A sane format would pick one.
// PSD, of course, uses all three, and more.
//
// Trying to get data out of a PSD file is like trying to find something in the
// attic of your eccentric old uncle who died in a freak freshwater shark
// attack on his 58th birthday. That last detail may not be important for the
// purposes of the simile, but at this point I am spending a lot of time
// imagining amusing fates for the people responsible for this Rube Goldberg of
// a file format.
//
// Earlier, I tried to get a hold of the latest specs for the PSD file format.
// To do this, I had to apply to them for permission to apply to them to have
// them consider sending me this sacred tome. This would have involved faxing
// them a copy of some document or other, probably signed in blood. I can only
// imagine that they make this process so difficult because they are intensely
// ashamed of having created this abomination. I was naturally not gullible
// enough to go through with this procedure, but if I had done so, I would have
// printed out every single page of the spec, and set them all on fire. Were it
// within my power, I would gather every single copy of those specs, and launch
// them on a spaceship directly into the sun.
//
// PSD is not my favourite file format.

The above comment was found in the source code of Xee, which is a “light-weight image viewer for Mac”.

/*
 * Abandon all hope, ye who enter here.
 * nah, but seriously. turn back now.
 */
// I am not responsible of this code.
// They made me write it, against my will.
//I am not sure why this works but it fixes the problem.

An unsettling feeling that all programmers experience at one point or another.

/*
This isn't the right way to deal with this, but today is my last day, Ron
just spilled coffee on my desk, and I'm hungry, so this will have to do...
*/

return 12; // 12 is my lucky number
// various hacks, pls don't look :)

Don’t worry, I won’t.

# Twas the night before Xmas
# And all through the office
# Not a creature was stirring
# Except for this poor bastard having to work on Christmas Eve.
__inline BOOL
SearchOneDirectory(
                  IN  LPSTR Directory,
                  IN  LPSTR FileToFind,
                  IN  LPSTR SourceFullName,
                  IN  LPSTR SourceFilePart,
                  OUT PBOOL FoundInTree
                  )
{
    //
    // This was way too slow. Just say we didn't find the file.
    //
    *FoundInTree = FALSE;
    return(TRUE);
}

The above code was found in the leaked source code for Windows 2004.

i  = 0x5f3759df - ( i >> 1 ); // what the fuck?

Found in Quake III source code.

// I don't know why I need this, but it stops the people being upside-down
x = -x;

Graphics programming is fun :)

# Explaining this would be too long, but I'm sure I'll remember.

According to the person who wrote the comment above, they didn’t actually remember… Much to everyone’s surprise, of course.

BOOL currentSizeIsAdequate = YES; // that's what she said
#if 0 // commented out until H3D pays us the money they owe us
    GL_DrawStereoPattern();
#endif

A classic way of dealing with clients that won’t pay.

stop(); // Hammertime!
Exception up = new Exception("Something is really wrong.");
throw up;  //ha ha
//imput sanitized to avoid: "EXTREME hacking"
$name = mysql_real_escape_string($name);
// this is a very hard to read file. good luck :-)

I love a challenge.

//I don't really understand this, just ask Jon, he'll know

Unfortunately, Jon had left the company three years prior.

// Add one to i
i++;
//drunk. fix later.
//i am so so sorry for what you are about to witness
protected function output_table(){

The name of that function does not inspire me with confidence.

// 
// Dear maintainer:
// 
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// 
// total_hours_wasted_here = 42
//
//i should have pursued dentistry instead
while(i < $num){
/// <summary>
    /// Class used to work around Richard being a fucking idiot
    /// </summary>
    /// <remarks>
    /// The point of this is to work around his poor design so that paging will 
    /// work on a mobile control. The main problem is the BindCompany() method, 
    /// which he hoped would be able to do everything. I hope he dies.
    /// </remarks>

Ouch.

// somedev1 -  6/7/02 Adding temporary tracking of Login screen
// somedev2 -  5/22/07 Temporary my ass

We’ve all come across “temporary” additions.

/* HP-UX sucks wet farts from dead pigeons' asses */

Found in the source code of a UNIX browser from the 1990s.

// If you delete the credits, I will fucking kill you.

A comment that was found inside a Joomla module.

// This is crap code but it's 3 a.m. and I need to get this working.
//We have to do this only because Exchange is a moron.
/**
 * Jesus Christ, how will I look my children in the eye.
 */

Facebook Comments