views:

15415

answers:

109
+86  Q: 

Humor in code

When you are writing code or naming products, which sources of cultural references are you most likely to draw from? Which reference sources do you think are more likely to be universally understood?

For example when findbugs sees that you've implemented equals() without overriding hashCode() it suggest that you implement it by returning 42 (a reference from HHGTTG)

Or why we have big endian vs little endian encoding, referencing Gulliver's Travels

Not that we should act unprofessionally with our code, but if you going to tell a person that they could only (watch/read/...) one (book/movie/show/...) which one would allow them to 'get' the most jokes?

+4  A: 

I used quotes from Office Space as strings in unit tests.

Mike Mazur
Some example of this?
OscarRyz
string multiline = ""Good evening Sir,my name is Steve.I come from a rough area.I used to be addicted to crackbut now I am off it and trying to stay clean.That is why I am selling magazine subscriptions.""; // http://www.imdb.com/title/tt0151804/quotes
Mike Mazur
It's not that I'm lazy; it's that I just don't care!
tsilb
+41  A: 

Not really a cultural reference, but I'm fond of using the HTML blink tag in my Javadoc.

yalestar
That's just mean. :P
musicfreak
Ha! I had a prof who said any blink tags in assignments (websites) would result in an automatic 0. Shame no one ever tested him...
Adam Neal
+10  A: 

I think one of the funnier ones I've seen is a perl function that had a hash named ofTheJedi (instead of some generic "this holds data" name).

Then only reason it was named that way was so the return statement was 'return %ofTheJedi'.

I've seen lots of HHGTTG references, lots of star wars references, and the odd Dr Who/Battlestar reference.

shelfoo
i'm incorporating this into my code pronto
Jon Erickson
+1  A: 

There's a database connection manager class in one particularly horrid third party app I work on. Every instance is called "connman".

While I'm sure it wasn't intentional humor, it seems appropriate. Sometimes, especially late at night, we break out laughing when we come across one of these.

AlexCuse
Why are you working late at nights with an employer? Jeez......
Click Upvote
+22  A: 

One wingnut I had the pleasure of working with used to work in the names of his ex-girlfriends to variable names.

Dim Jessica as String

Ugh.

Galwegian
thats a strange until you go to clean up your pointersExGf lisa = new ExGf(); ....delete(lisa);but event that doesn't seem very thereputic.
pfranza
Even worse, it looks like he's using VB so he can't even terminate his ex-girlfriend string.
polara
Does he refactor all his code when he gets dumped? :)
steffenj
@steffenJ: those are his ex-gfs; he is already dumped by them. new exgfs will have to wait for new code to be written I guess ;)
If you name your functions/methods after girls, you can "call" them.
tsilb
and if your classes are named after girls, you can inherit them?
Click Upvote
and if your HTML SELECTs are named after girls, you can 'check' them
Jens Roland
and if your processes are named after girls, you can kill them
Jens Roland
I think someone took that joke past the end of the index.
uzbones
+1 for wingnut!
Harry Lime
+1 for past the index. I almost sprayed coffee.
Pekka
throw new IndexOutOfRangeException();
Tom Savage
+32  A: 

Monty Python references. But then, I'm a Python programmer.

ddaa
Makes perfect sense! :)import spanish-inquisition;
steffenj
I did a project at uni once involving Knights and tournaments. Bonus marks were awarded for applicable Holy Grail quotes.
Zooba
This is specifically encouraged in the official language reference.
Colonel Sponsz
Them: "I would redesign the architecture."Me: "It's only a model..."
Joseph Gordon
@steffenj: nobody imports spanish-inquisition :)
Muhammad Alkarouri
As i've told to my colleague: "-This project is dead! -No,no, it's testing, look!"
creitve
+31  A: 

There are so many funny comments in the OS-world. I like this one:

return(0); // Another brick in the -Wall

(It is one of those returns that never could be reached.)

unexist
+8  A: 

I try to avoid doing that. Can make it more difficult for others with different backgrounds to maintain the code.

Brian Knoblauch
Yeah I've been tempted many times to make a snarky comment, but then I remember the folks for whom English is a second language. It's hard enough for them without having to figure out a sitcom reference.
JosephStyons
Ditto that. Often times humor is quite relative, even without a language barrier. What you think is funny somebody else might consider idiotic.
Nik Reiman
You guys must be a lot of fun at work.
korona
lol, brian knoblauch is that dude
@josephstyons, I think you should do that for precisely that reason, would be funny if they couldn't understand a sitcom ref and went to a supervisor and said 'do you know what x means..?' LOL
Click Upvote
And then you realize, that sitcoms are not, perhaps, the most funny thing in the world :)
shylent
+1  A: 

23, 42, 69

For extra obscurity, I sometimes convert them to hex before.

Thorsten79
I've seen 666 used as well.
Aardvark
23 is a Discordian / Illuminati reference.
wnoise
I'm partial to 1701 myself
Wes P
I usually go with 1702, myself. A great book, that was.
Lawrence Johnston
Do you mean 2702? I think @Wes P was referring to the Enterprise, not Cryptonomicon.
Adam Lassek
+15  A: 

In unit tests, I'll do HHGTTG, Office Space, Idiocracy and occasionally (only occasionally) Star Wars references.

In my production code, no. No way. I try to keep that as professional as possible, down to the comments -- at least what gets checked in. Not only does it make my life easier when I'm maintaining it six months down the road, but it makes the lives of anyone else who has to maintain it easier. Humor has a place; in my mind production code isn't it.

(That said, I'm not above a little easter egg in an about box with some humor -- as long as it's zero-impact on the application's functionality.)

John Rudy
Why is it that 'professional' has to = 'so serious we avoid any attempt at humour'. There's some arguments for easter eggs, be it in the code, or in the UI. We're human. Why can't our code be human?
DA
@DA: Because the next guy who needs to read/maintain it may not get the humor. It doesn't add value to his experience. Additionally, clients who are being billed hourly and may expect to audit the code often don't appreciate it -- they see it as time wasted on their dime.
John Rudy
Another reason not to write funny code is that if it happens to break there, it could look really bad. If it's a serious bug you could end up looking like a clown.
dangph
You're against jokes in comments hidden in the source code, but not in about boxes every user can see?
Michael Mrozek
I agree not to write funny code, with exception of about box easter eggs, however what's wrong with funny comments. I'm usually so depressed when I check out code at work, I would love to find occasional humor (even poor attempts).
jamone
+1  A: 

It might be funny in the code that you write, but it's maddening to debug someone else's code that's littered with this kind of trite.

MegaHAL
Perhaps you meant tripe, as trite is not a thing nor is it relevant to bad comments... sorry haha.
slude
vocab nazi slude++
Max
I actually liked the idea of "trite" used as a noun and came here to say so.
eyelidlessness
+4  A: 

Another one I used to enjoy when I did COM programming was to place the following above a QueryInterface call:

// QueryInterface for the Straighty Interface

or, alternately:

// QI for the Straight Guy
yalestar
+2  A: 

This wasn't used in any program, I just thought it was funny.

<?php
$iShower = $_GET['clean'];
if ($iShower) {
     echo getdate();
}
?>
VirtuosiMedia
I think the implication is the wrong way round. Surely if (!$iShower) { !getdate(); }If showering is a sufficient condition then please let me know where you live
Leigh Caldwell
I think you need an area where the size of the intersection of dating women and desperate women is larger than the size of the set of showering men. No, I don't know where that is.
Tetha
index.php?clean=0
eyelidlessness
I'll admit it: I had to read the comments to get the joke D:I think it would have been clearer without the echo.
Wallacoloo
+17  A: 
for(int c = 0; c < 10;)
{
   c++; // < get it?  c++ ?  it's so... literal
}
Pyroglass
Perhaps it's a speedup loop?http://thedailywtf.com/Articles/The-Speedup-Loop.aspx
HoboBen
C++, get it? C plus plus
mattlant
No, we lost you ...
OscarRyz
Then the whole world is lost. God help us all :P
mattlant
People just pretend they don't understand puns. That or i have a horrible sense of humor.
WolfmanDragon
I wouldn't beat yourself up about it. Took me a while to get it. And once I did I didn't find it funny because... well... I found it funny for about 10 minutes when I learned it my freshman year of college... :-\
Wes P
I thought it was pretty funny.
Pim Jager
I got it, but wish I didn't.
Dour High Arch
The code says "c++", and C++ is a programming language (whose name comes precisely from the fact that ++ is the increment operator in its predecessor language C). Is that it? Is that the joke? Is that a joke?
ShreevatsaR
I would normally write ++c;
Daniel Daranas
@ShreevatsaR: lol I get it now tnx bro
Daniel
C++ -> make C larger but use the old version :)
martinwguy
why don't you just go c = 10...
Tor Valamo
+2  A: 

My test data for Gliffy's API is all based on Simpsons and Futurama. For example, the account named "BurnsODyne" has diagrams like "Reactor Control UI", "Mayoral LAN", "SNPP Domain Mode", and "Booze Database Design". A personal account owned by "[email protected]" has a flowchart called "Circuitous Plan to Get Hands Back". Test data just has to be kept interesting. I actually made them realistic, too:

![SNPP Domain Model] (http://www.naildrivin5.com/davec/SNPP.jpg).

davetron5000
I guess inline images are no allowed? Weird that the help told me how to do it and previewed it and then didn't render it....
davetron5000
I think it may be sanitised out. Jeff had a blog post recently about this. Obviously you're welcome to force yourself to execute arbitrary code (hence the preview working), but it would be better if it didn't. Uservoice, anyone?
Zooba
+2  A: 

So this isn't directly answering the question - but definitely is good not to take yourself to seriously when you're programming - have a good time and don't worry - that proverbial next programmer will be smart enough to figrure out what's going on regardless your oddball sense of humor.

Had a senior project I was working on for my under-grad degree - we had a "project manager" who also participated in some of the coding. I was almost in tears when he took personallly a comment I made about "the stupid database" or something like that - he thought I needed counseling or something (not that I don't)... but again, let's not take ourselves to seriously, cause no one else does.. :)

A: 

This is definitely not mine, but the Sun hme driver provides lots of fun!

http://kerneltrap.org/node/542

Jeremy Brown
A: 

We have a series of scripts that manage our automated promotion process named Travis and Franz (for no particular reason aside from the whims of the programmer who named them), and a cleanup script named Alice (from the maid in the Brady Bunch).

The Brawny Man
+44  A: 

I giggle every time I shorten "Assembly" to "ass" in .net:

var myAss = this.GetType().Assembly;
Matt
I was once asked to go back and rename my variable names for this exact reason.... because someone had to read it aloud in a meeting.
hometoast
How does one adequately read code aloud? Do you have to specify where the semicolons are?
John Rudy
I'm thinking more along the lines of something like: "When I call function X on 'myAss', it throws a NullPointerException. We need to make sure to double check that 'myAss' is not null!"
Outlaw Programmer
LOL LOL LOL! :) ... I just remembered i had that in my own code somewhere, but it didn't even feel weird to name the variable containing an Assembly "ass". It occured to me only days later when i came back to this code, and henceforth every Assembly var is named "ass" now.
steffenj
But "myAss" is so much better, i guess i have to refactor! :)
steffenj
I had the legitimate opportunity to use name a variable "perfectPair" the other day. So I did :-)
endian
Once I saw an application called MIARS, short for M*** Integrated Analytical Reporting System. The conversation was supposed to go: Where did the numbers come from ? ...
ConcernedOfTunbridgeWells
Did you every pull anything out of or put anything into ... er nevermind. http://tinyurl.com/6ue3t ;)
Edward Kmett
I shortened "Performance analyst" to "perf_anal" once. The perf_anal himself wasn't too impressed.
Graeme Perrow
I just happen to have started working on a project where Assessments are filled in and processed. And every programmer coding before used for (Assessment ass : assessments) { if (ass.isOpen()){...}...} it's fun to work with this code :)
Peter Perháč
As long as you don't start making ASSembly MANagers...
Artem Russakovskii
Very often when I'm typing "add" I miss by one button so it ends up as "ass" so i try to call strange methods like assItem() etc...
Stein G. Strindhaug
A: 

I've never done it in code for work, but when I was in school I always enjoyed overly long acronyms for my app names. Also, recursive ones are fun. I named one MOOVIE - Movie Object Oriented Visual Information Exchange.

Adam Neal
That's not a recursive acronym ("Movie" is a word)
advs89
+1  A: 

One of my favourites that I have come across:

my $ofTheJedi = x;
return $ofTheJedi;
Rontologist
I beat you to it.. or is that bet you to it?
shelfoo
I got beaten as well :(
Geo
lol so many of this joke here
wrongusername
+10  A: 

This is from the app we're currently working on. For all fans of dodgy 80's pop:

if($res) {
    $karma = $res['Karma']['karma']; // karma karma karma chameleon
}
David Heggie
This is a song ?
Agusti-N
http://en.wikipedia.org/wiki/Karma_Chameleon
David Heggie
+21  A: 

In the days when Pascal was a popular teaching language and a common exercise was to write a program to output graphics using a pen printer (one of those that moves a pen across a page, raising and lowering the pen to draw) we had a lecturer who used to delight in the pointing out the pitfalls of the convention of naming pascal variables by joining words and in fixing capitals, i.e. the common boolean variable name :-

PenIsUp

Cruachan
I did worse than that. I stored the state of the pen in the variable PenIs--and did not notice what it spelled until I was done.
Loren Pechtel
you mean a plotter http://en.wikipedia.org/wiki/Plotter
Brad Gilbert
Aye, that would be it. They were endlessly fascinating to watch, especially the ones that moved the pen in two dimensions (some moved the paper and the pen instead).
Cruachan
+3  A: 

I prefer unintentional humor...

Legacy code is perfect for that.

Dim intOrderID AS Long

Or sometimes when the comments have long ago become out of sync with the code they were referring to.

Reality truly is stranger than fiction....

Kevin Fairchild
+1  A: 

A friend of mine wrote a program that would communicate with another via two pipes. One for each communication direction (send/receive). The variable that held the descriptor/handle for the pipe for receiving data was named "bagpipe".

EricSchaefer
i think d-bag would of been a better name for your friend
+4  A: 

My favourite: 42, second place: Towel. And just to show that I have read other books too (3 or 6, depending on the way you count): Precioussssss...

Treb
+90  A: 

Microsoft Code has lots of good comments (Taken from Windows 2000)

// The specific idiot in this case is Office95, which likes
// to free a random pointer when you start Word95 from a desktop
// shortcut.

or:

private\genx\shell\inc\prsht.w:
// we are such morons. Wiz97 underwent a redesign between IE4 and IE5

private\shell\ext\ftp\ftpdrop.cpp:
// We have to do this only because Exchange is a moron.

private\shell\shdoc401\unicpp\desktop.cpp:
// We are morons. We changed the IDeskTray interface between IE4

private\shell\browseui\itbar.cpp:
// should be fixed in the apps themselves. Morons!

Or:

private\shell\ext\tweakui\genthunk.c:
/* CallProc32W is insane. It's a variadic function that uses
* the pascal calling convention. (It probably makes more sense
* when you're stoned.) */

Finally, this makes you wonder about the build process over at MS:

/*       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!IF YOU CHANGE TABS TO SPACES, YOU WILL BE KILLED!!!!!!!
 *       !!!!!!!!!!!!!!DOING SO F**KS THE BUILD PROCESS!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 */
FlySwat
Isn't that a little bit dangerous to post that here, I mean could this be a copyright problem or so, even so it's funny?
André
I think these have been posted elsewhere, publicly, so there is little danger. Of course IANAL...
Keithius
These are from the leaked copy of Windows 2000 source that hit the scene years ago, I don't work for MS.
FlySwat
I wonder if all of the 'moron' quotes were posted by the same obsessive programmer! lol
Tony R
I know that those where posted elsewhere already, but it's still a possible prob, just b/c others did it, it's not automatically legal, but maybe I'm just über concerned
André
I take comfort in knowing our dev group isnt alone in needing anger management
MikeJ
Doesn't changing tabs to spaces break `make`? and if you do it on my make files, I might kill you.
dlamblin
There are lots more of these over here...http://www.kuro5hin.org/story/2004/2/15/71552/7795
Jason
Using spaces instead of tabs breaks make as well - including GNU Make I believe...
Graham
fair use, guys, this is most definitely fair usage..
Jasper
@Fly Swat-See http://www.microsoft.com/presspass/press/2004/feb04/02-12windowssource.mspx Also @Janson 's link is cool!
giddy
+6  A: 

It's all fun and games, until a bug makes your attempt at humor visible to the customers...

Joe Strazzere
As seen in "We Burned the Poop".http://thedailywtf.com/Articles/We-Burned-the-Poop.aspx
FlySwat
Very, very, very true. Not that I have any first hand experience with this...............
Max Schmeling
Psh. The customer is the audience. (Just kidding. [Sort of.])
eyelidlessness
Yes, as we once had "Please stand by XXXXX.com is grunting a sculpture" noticed by our content editors.
Chris Ballance
'back in the day' we used to remote into client PCs and do fixes on site for emergency situations. Nothing like cracking open the code and reading a comment: "Way to go Bob, taking a simple problem and making it fucking more difficult". Especially fun when the customer is reading the screen.
SomeMiscGuy
A: 

Well, when just testing stuff out I used to name my command objects Arnold:) That and a lot of swearing in test strings:P

Antonio Louro
+9  A: 

If you're going to put jokes in your code, PLEASE for God's sake do it in the comments. There's nothing more annoying than variables or methods with "hilarious" names. It really does make the code more difficult to understand.

But I'm all for funny comments. (And there's more to humor than referencing obscure TV shows.)

JW
+2  A: 

Personally, I keep the comments straight forward and to the point... The svn check-in logs however... recently full of references to Dr. Horrible's Sing Along Blog.

kae
+2  A: 

This didn't directly relate to the code in the script, but I wrote a VBScript called psexecWizard. It basically called psexec en-mass based on some database criteria and did some other random/cool stuff. In between the functions, I made comparisons between psexecWizard and "Pinball Wizard". Other wizard references eventually cropped up (allusions to the Washington Wizards, Wizards of the Coast, and Harry Potter, boy wizard).

sample:

' Pinball Wizard was written by Pete Townshend of "The Who".  Dan Coates* wrote PsExec_wizard.  According
' to both authors, each item was "the most clumsy piece of writing [he'd] ever done."

' * Not the more famous Dan Coates that wrote "Lean on Me", but the less famous one who was in a
' a cappella group YouTube video performing Nintendo songs.
Dan Coates
+10  A: 

There is an xkcd forum thread with quite a nice collection of Funniest/Most Annoying Code Comments

Jacob
A: 

I like belittling my programmer-colleagues in my code comments. It makes me feel better, and also tells me whether anyone reads my comments.

David Hill
Bad idea. You never know when your comment will come back and bite you.
SLaks
I think its a great idea. I'd write a comment about you that says "Has no sense of humor, and dresses like a bag lady."
David Hill
+2  A: 

I don't know about anything funny.. but it's always a hoot to lie in your comments. Not little white lies, but huge blatant ones.

'//do not remove following code or app will stop running
Dim n as string
For n = 1 to 10000000
   n = n & rnd()
Next
DaveJustDave
Looks like a loop to introduce a delay. That was often used to work around bugs (i.e. the Borland Pascal runtime error on newer PCs) or when there is an external component that takes a moment to initialize. In any case, that code will break at some point in the future when run on a faster machine...
Michael Stum
shouldn't n be an integer? Why a string?
Wallacoloo
Because if the snippet truly is a time delay, string concatenation would slow it down even more.
Cory Larson
+86  A: 

Ok, not actually real production code, more compilable doggerel...

public class MohammedAli {
  float like_a_butterfly;
  string like_a_bee;
}

and the somewhat more elaborate:

public class LunchOrder {
    double cheeseburger;
    char grilled;
    long drink;
    short cake;
}
Dylan Beattie
Slightly upset that this made me laugh! Feel so.. cheap!
DavidWhitney
class Employee{ short hours; double pay; long lunches;};
Adam Rosenfield
I always declare the first double "d"
cciotti
Maybe short coffee?
tunnuz
More like class Employee { long hours; short pay; short lunches; }
Joe
class Divide { private function youreNotInvited() { return "from whence you came!"; } }
oops
`class CEO { short hours; long perks; BigInteger pay;} `
fastcodejava
or the infamous `int eger;`
slacker
+31  A: 

I once saw an especially clever comment used Morse code as an implicit message....

// .... . .-.. .-.. ---  .-- --- .-. .-.. -..
// begin section
// .... . .-.. .-.. ---  .-- --- .-. .-.. -..

Love it... +1 with sentiment that shenanigans should be in comments and not variable names.

Michael Easter
Spoiler - helloworld
Guy
http://morsecode.scphillips.com/jtranslator.html :-)
lpfavreau
i dont get it, someone care explaining?
Click Upvote
".... . .-.. .-.. --- .-- --- .-. .-.. -.." is Morse code for "HELLOWORLD".
cpeterso
i first thought my browser had a render-error
Marenz
Brilliant!!! I am gonna put lot of Morse legacy n my code!!! ;)
Microkernel
+5  A: 

My favorite is a comment a co-worker added to a safe-delete function we had in c++. It was very hackish, but it protected from some null problems in a code-base that wasn't checking nulls often enough.

    class WidgetBase
    {

      void SafeDelete()
      {
        if (this)
          delete this;
/*
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing, end them. 
*/
      }
    }
loudej
delete is supposed to include a null test like this anyway (as in, it won't attempt to free a null-pointer). Nice comment though.
Zooba
haha. tell him calling something on a null pointer is undefined behavior :D
Johannes Schaub - litb
@Zooba: My C++ compiler from 1998 didn't check null.
Joshua
@Joshua: but it did figure out what null.SafeDelete() was?
MrKishi
+2  A: 

I would say, stay away from humor in code unless your program is written in lolcode.

lolcode.com

+1 for the awesomeness of lolcode
Wes P
+17  A: 

Once I was going through some old application code for maintenance and I came across these comments within an empty function block:

"Alex will be coming tomorrow to write code here." It was commented with a very old date. Obviously, something happened to Alex or else it would not have remained empty.

I was curious and made some enquiries about Alex with some old timers. One of the guys mentioned that it might have been the guy who admitted he could not code from Day 1 and needed some training. He was fired the same day.

Not sure what happened to the guy who put the comments in the first place.

Gulzar
oh my god. hahahahaah
Click Upvote
I hit a similar comment after a few hours debugging, a lovely note to myself saying 'TODO: Fill this in. I didn't know whether to laugh or cry at the time. I laugh about it now though :-)
Dan F
+2  A: 

I'll throw in random stuff when I'm working on a very difficult problem, due to my inability to think of appropriate variable names. I tend to try and tell a story to keep my excitement

$self = new User();
while($self->hungry()) {
    $bacon = $pig.Substr(...);
    $breakfast = getValue() + $bacon;
    $self->feed($breakfast);
}
SeanDowney
A: 

When ever I test a system that needs information about people I always use The Simpsons characters. There are lots of them and when I see "Ned Flanders 132 Evergreen Terrace. Springfield MA I know it's one i created.
(yes, I know it's the wrong state but I'm from MA and it's a debatable issue) It's also fun to see which of my co-workes notices it first.

Ben
k.. well hate to break it to you, but the simpsons are so 1990's. family guy for the new millenia1!!
Awesome - small heads-up though, the Simpsons are at 742 Evergreen - which would make Ned either 740 or 744. :-)
Fritz H
+41  A: 

SEX (SignEXtend) mnemonics was removed from the Assembly language for Intel microprocessors but ANL and ORL (Logical-And and Logical-Or) were allowed.

alex
Source here: http://www.catb.org/jargon/html/S/SEX.html
analytik
+2  A: 

I sometimes use a pattern where a temp table has a boolean column named Kevorkian, initialized to true for all records. The process does some fancy dancing wherein records may be added, and Kevorkian may be set to false for certain existing records. Finally, a delete query removes all records where Kevorkian is still true.

I tried to think of a more serious name for a flag that means "after careful and mature consideration, this record still wishes to commit suicide" but Kevorkian was the best I could do.

-Al.

A: 

Geeky pop culture things. Like Johnathan Coulton songs, or an XKCD comic. Maybe an obscure video game reference (like Leroy Jenkins or something). Generally my source code humor comes from whatever tickles my fancy at the moment.

Wes P
+3  A: 

We named an internal application LIGERS. Needless to say, we were thrilled to be able to fit in a reference to Napoleon Dynamite.

Ben
A: 

Wow. Just wow. This thread is awesome. I personally like a bit of humour in code, it keeps me awake on those extra early mornings when the 9:30 scrum is a bit too early.

On my last job we had a particularly colourful couple of coders who liked to get subtle jabs in through the comments. My favourite was one that had an excellent swear density, about every 4th word, and a blatant statement that he a) did not want to write this code and b) we would be better off using another product.

I thought the swearing might be a bit much but hey that little chunk of code could get me through even the most boring meetings.

smaclell
+47  A: 
// every time you call this a kitten dies somewhere

O(n3) method follows...

seanb
A: 

I came across a quite funny method, used seriously in the code, it made me laugh. :D. It did something, but it was hard to decipher what it did.

void Foo() {

// Some spaghetti code here 

}

Apparently there was no method 'Bar', I was disappointed.

+46  A: 

I usually write very straight-edge code, and try to name things as clearly as possible. But sometimes a good, logical name turns out to be funny.

I was building a "safe search" filter for a popular online video site. You may have used it. It just keeps the sexier videos out of your sight unless you explicitly toggle your settings to include them.

So I needed to name a method for bringing the sexy videos back into the user's video queries.

I couldn't help myself:

UserManager.bringSexyBack();

It's in production. Millions of people bringSexyBack() every day.

keparo
It says for a popular online video site, that could be any number of ... No wait ... your probably right.
Brad Gilbert
That's gold! I bet it plants an earworm whenever you look at that code though :-)
Dan F
Hrm, now what video site could that be. Could it be... Veoh, Mr. Kelly Patrick Robinson?
Artem Russakovskii
+6  A: 

One of my favorites was a file with in the header something like
// Author: Mike
and a bit later, in a function, something like
// Mike: whoever wrote this code should be put against the wall and shot

Anyway, be very careful about being too clever. Blowing off steam in comments is fun, but maintainability should always trump funny. Never, ever, try to be clever with variable naming.

Joeri Sebrechts
Lol, i really wanted to upvote this but have run out of votes
Click Upvote
+3  A: 

Got some nice comments with no reference at all :)

'2002 07 22 [Jon] Temporary fudge for AMEX
'2005-02-23 [Dominik] Temporary is relative ;)

(It's still in there ;) )

BlaM
A: 

We had a project whose title abbreviated to AU, so quite a few (private) functions were

gold_this() { ...}

or

gold_that() { ...}

after the chemical symbol ...

It was humour, although not particularly funny.

Unsliced
+1  A: 

I had written some code that needed to know if the person reported last month had passed on during the month. I created the method ISeeDeadPeople(...) as bool

osp70
+63  A: 

I just found this Stored Procedure in our database.

ALTER PROCEDURE ORly 
AS

print ' {o,o}'
print ' |)__)'
print ' -"-"-'
print 'O RLY?'
print ' '
print '{o.o}'
print '|)_(|'
print '-"-"-'
print 'YA RLY'
print ' '
print ' {o,o}'
print ' (__(|'
print ' -"-"-'
print 'NO WAI!'
Jason Baker
i'm added this to every DB i ever create. haha
Jon Erickson
+40  A: 

I've always waited for the occasion to write the following comment inside a C++ class declaration with private members and friend classes:

// Only friends are allowed to see each other's private members.
Ates Goral
+67  A: 

Taken from the xkcd comic Random Number

int getRandomNumber()
{
    return 4; //chosen by fair dice roll.
              //guaranteed to be random.
}
John Chuckran
That is possibly one of the funniest things I've ever seen.
localshred
I'm getting tired of xkcd though.
The Wicked Flea
The book version has an extra ';' between the () and the line break. But, hey! it's the RFC 1149.5! It's the only logical random number to return, right?
luiscubal
-1 Every time you push a good xkcd joke one step closer to becoming just another overused internet meme, god kills a kitten. Please, think of the kittens.
Evan Plaice
A: 

There's some code at work along the lines of:

date midnight midnight = date("8:00")

Slapout
A: 

I worked with someone who put a variable named NotSoFastMonkeyBoy in the application. This popped up in an error message where some customers could see it. Management was not amused.

At the same place was a library for making multi-step wizards and named everything according to a wizard theme. Each page of the wizard was a spell, all the spells were in a grimoire, and the current page was pointed to by a wand.

Jeff Cuscutis
+81  A: 

Once, a couple of years ago, I was working with some custom XML for an installer. In my late night frustration I just couldn't figure out why this one "feature" wouldn't work. That is, until I got this error message:

The Product element contains an unexpected child element 'Bastard'.

This was totally unintended and has kept me laughing to this day...

Dashogun
+5  A: 

To answer your question, I suspect Hitchikers Guide to the Galaxy is the single book from which the most programmer humor comes from, but that may just be personal experience. I have seen very many comments and variable names that came from there.

But other than that, we're all over the board on our references... I remember seeing one comment in a chunk of perl code that had given the developer a lot of trouble:

# Touch this code and die like Biggie and Tupac
.
.
.
# /Touch
Adam N
+1 great! .
scraimer
+10  A: 

Magic number in Java class files: 0xCAFEBABE

[localhost ~]$ hexdump -C Foo.class  | head
00000000  ca fe ba be 00 00 00 31  00 46 0a 00 14 00 1f 09  |Êþº¾...1.F......|
Maglob
I like this place. It's right up the street from the 0xDEADBEEFCAFE.
Don Branson
+1  A: 

The funniest thing I ever saw was in a c# application to replay captured drawings on the screen. In between the individual drawing of the samples of pen positions was a call to a function waitABit();, which was defined as follows:

void waitABit()
{
  for(int i = 0 ; i < 1000000 ; i++);
}
One like this caused us a lot of grief. If was compiled code designed to run on a 286. We had to keep a 286 PC in working condition until the whole line was retired around 2002. Worse yet the DOS version installed on it was German. Every emulator or slow down we tried cause the program to fail.
Jim C
A: 

In java code of huge old application I saw quite funny comment

// Fellow, modify this method if you understand EVERY SINGLE LINE in it
Michael Dubakov
+20  A: 

I've twice had to create a Log class for message logging. Both times I put this comment in the class header:

// What rolls down stairs
// alone and in pairs
// and flattens the neighbor's dog?
// What's great for a snack
// and fits on your back?
// It's log, Log, LOG!
T.E.D.
Lets not forget that its "Big its heavy its wood. Its better than bad its good"
Jon P
How 'bout LOG for girls?
borisCallens
Its fun for boys and girls
Brad Gilbert
I am so putting this in all my headers from now on.
musicfreak
+1  A: 

In my younger days When writing one-off perl programs I admit I had a penchant for just emitting code with colloquial meanings like:

open(FOO,"...") or die horribly;

or

foo() until $hell_freezes_over;

Though, that said, I try to make very few cultural references in my code.

Edward Kmett
+53  A: 

When I was using VB6, I often had my error handling look like:

On Error GoTo Hell

I used it again when writing code in VBA for access. My then very Christian manager nearly had a heart attack when he saw it, and made me change it :(

RichieACC
FAIL @ religious lack of humour
Jens Roland
I am going to use this! goto hell;
cpeterso
That was in Futurama, in the robotoly church: 10 sin 20 go to hell but they forgot 30 ... 40 profit!
streetpc
I would upvote this, but you have 42!
Wayne Werner
haha!! Thanks Wayne!
RichieACC
+36  A: 

My favorite, and one I now sometimes borrow was seeing this in a Makefile:

love :  
     echo "not war"
dwelch
On FreeBSD system is built into the make.
Wergan
+6  A: 

Looking through some code from earlier this year, I found some silly comments.

In a C file that converted to/from Roman numerals, the "last update" timestamp had the year written in Roman numerals. That was the only file in the project that had it. Later on, in another number crunching file, it included some things regarding the above-mentioned Roman numerals:

#include "roman.h" //He has a wife, you know... Know what's she called?"

There's also a function I first encountered in Nethack and lovingly adopted: strkitten(char*,char);

Kawa
So what does strkitten do then?
Alan
Well, if strCAT appends (concatenates) an entire string, strKITTEN appends only one character, obviously.
Kawa
+1 for the kitten. Everyone loves kittens!
Wayne Werner
A: 

I have a habit of making testing values the names of fictional countries. Leading to several co-workers playing "guess the movie" once.

J.T. Hurley
+40  A: 

Here's another one:

while ("my guitar gently weeps") {
...
}
unexist
Might be funnier if you spelled 'weeps' correctly :)
Tim
I am going to adopt this one.
Konrad Rudolph
+1  A: 

A certain project I worked on had a LOT of complicated, big-ball-of-mud code. One of the older functions is prefixed by a quote from Through the Looking Glass:

/* "It seems very pretty," Alice said when she had finished it,
    "but it's rather hard to understand! Somehow it seems 
    to fill my head with ideas--only I don't exactly know what they are! 
 */

IMHO funny comments are OK, but funny-names or funny-values for variables are horrible:
-Why do we have a String login_is_ok and why does it contain "Listen, I'm not crazy ... yet"?!? +Well, one of the original developers thought it was funny, ROTFL-funny even.
-Aaargh!

Piskvor
A: 

I inject a number of things in code that only I think are funny. :)

For example, instead of naming an interface IPacketViewer, I might name it ISeePackets.

Theoretically, I could mention my children's names in method parameters, assuming I was using the Dependency Injection pattern.

Don Branson
+4  A: 

To combat out project being offshored to Cambodia we try to include the occasional reference that other cultures might not understand.

i.e.

To find the parent site in MOSS:

WhoIsYourDaddy();
Chris Ballance
+3  A: 

In a class to manage several threads:

public Collection getRuns()
{
    return new ArrayList( runs ); //return chinese food
}
Joseph Gordon
+1  A: 

I really liked this one :


int OF_THE_JEDI = some value;
// code does something here with var
return OF_THE_JEDI;
Geo
ok you are like the 4th person to post this, please come back when you get something original
+18  A: 
double pi = 3; //M:find correct value 

This "inaccuracy" was hidden in the code for about 3 years before I discovered it.

Chris
Shouldn't the compiler have found it first? ;-)
Adam Liss
Whats wrong with Math.PI() :-) (assuming .NET or Java)
Anders Rask
+4  A: 
If(true)
   //Just to be sure =)

Lol

Rulas
+48  A: 

I was writing a class to crawl the web so naturally the class definition was like this:

public class WebCrawler //: public SpiderMan, private PeterParker
{
};
vengafoo
Might be more appropriate for a Facebook scaper, pretty funny nonetheless.
Peter Turner
+1  A: 

My default new JSP text in eclipse used to read: "This is my JSP."

It now reads: "This is my JSP. There are many like it, but this one is mine."

A: 

I write for a lot of school districts. I tend to keep humor out of my code but my test database has the teachers as the actors that played the Doctor and the students as the various companions over the years.

monkeypushbutton
+35  A: 

I once worked on an app that had an interface for auto handling persistence of "dirty" objects. The interface was named...

ICanBeDirty

... and still makes me laugh, the guy who wrote it hadn't even realized that it was funny when I asked him about it.

Patrik Hägne
Wish I could upvote more than once, LOL.
Leslie
A: 
die (Strings::get('Obituary') . $e->getMessage());

or

$validArchType = array ('A-Frame', ..., 'McMansion', ...);

or

define ('DEVIANCY_OR_MALFEASANCE', -1);

or

<string key="VICE_PRESIDENT">Just making sure Kathy is paying attention.</string>
Clayton
+2  A: 

This isn't really humor, but I find it funny. This is the fast inverse square root function from the Quake III source code. It uses some crazy hacks to get results that (at least, at the time) are up to four times faster than (float)(1.0/sqrt(x), even though sqrt is usually implemented in assembly.

Line 10 makes me laugh. Maybe it's just how ridiculous the whole thing is, and I can see John Carmack laughing while writing something so strange.

float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;  // evil floating point bit level hacking
    i  = 0x5f3759df - ( i >> 1 ); // what the fuck?
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
    // y  = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

    #ifndef Q3_VM
    #ifdef __linux__
     assert( !isnan(y) ); // bk010122 - FPE?
    #endif
    #endif
    return y;
}
Matt Olenik
Carmack actually didn't write it. http://www.beyond3d.com/content/articles/8/
Hawker
awesome article Hawker thanks!
m_oLogin
A: 

In FoxPro:

set bug on

or:

set bug off

lmsasu
+18  A: 

In C++:

 #define true false // happy debugging losers
Brian R. Bondy
Actually, not in C. Only C++ defines the boolean type.
Billy ONeal
@BillyONeal: Yup fixed.
Brian R. Bondy
+1  A: 

There are some comments that are fun but really useful. I remember one program made with C++ (Visual Studio 4 or 5) where I found the following comment (I translated it for the sake of clarity).

double x = 0.0; // DON´T TAKE THIS OFF!!!

Note that the variable x was not used anywhere. The funny part is that if you deleted the line the program did not compile anymore. The error? If I remember correct it was something about struct alignment.

fbinder
+3  A: 

For the rare occasion I need to raise exceptions, I have reserved a special identifier:

var up:Error = new Error();
throw up;
Simon
What language is this?
missingfaktor
+1  A: 

I don't remember the exact original code and it no longer exists because it was a horrible hack but here's the story:

It was shipping date and we still had some "cleanup" to do, the final tests were running and only one, tiny bug was found by the tester: randomnly, when the user reloaded the application with the command "[app_name] reload" he couldn't get back the prompt and had to press Ctrl+C (the reloading worked fine, just the prompt didn't return sometimes).

The application was run by a bash script that managed more than one child process in the background, and to identify the current in scope process we named it as "me".

So we came up with the brilliant idea to kill the child process that do the reload after it was done:

doReloadInBackground
sleep(5) # Aproximately time taken to reload the application
kill $me # , please

It was a rather stressful day...

German
+1  A: 

From the C++ standard headers included with Mingw (and perhaps others...)

basic_ios.h:
*  @return  A bit pattern (well, isn't everything?)

basic_string.h:
*  Documentation?  What's that?
Thanatos
+16  A: 
char coal;
short cut;
long way;
float assets;
string tanga;
double penetration;
object slide;

UserPermissionException up = new UserPermissionException();
throw up;  // lol

return off;// the Jedi;
codymanix
I can`t stop laughing :)))))))
Siblja
`int eastwood` and `char guevara` – we had those at uni ^^
poke
I prefer `double entendre` - not as explicit :)
gnud
public double entendre
codymanix
+5  A: 

from OpenRasta

public interface IHas : INoIzObject {}
serialseb
+5  A: 

A friend of mine uses this status message when he's asleep :)

while(awake) sheep++;
George Profenza
I think I'd prefer do { sheep++;} while(awake)
pfranza
A: 

I wrote baNdit, a Firefox extension that adds a lot of useful features to banniNation.com. One of the features is marking posts that have scores above a certain threshold with an image, or if you've told it to pay attention to a particular user, it'll mark the post with a different image. The name of the function that handles this is:

PublicDefenderChristineSullivan : function() {

Google it if you don't get the reference.

Chris Doggett
+6  A: 

acceptable usage of breaks and contunues in java:

dance:
while(some_bool){
    //something in loop
    ...
    if(some_condition)
        break dance;
}

and:

the_assault:
while(something){
    //body
    ...
    if(condition)
        continue the_assault;
}

or something to that effect.

Victor
+7  A: 
<?php $_GET['rich'] or die('trying'); ?>
Hilton Perantunes
+3  A: 

Scott Meyers in comp.lang.c++.moderated:

using namespace std; // so sue me
Will
+1  A: 

I tend to name temporary classes, scripts, and variables as "mattayu". As in:

public class Mattayu
{
   ... some temporary coding to be used and thrown away
}

I actually had someone ask once, "What's a 'mattayu'?"

To which the answer is, naturally, "What'sa matter me? What'sa matter YOU???"

Caro Cogitatus
A: 

At my employer, we've named our databases and some of the machines in your development environment after The Big Lebowski characters and common themes.

For instance...

"TheRug", "TheBriefcase", "Donny" and "Walter"

I won't elaborate on what is exactly named after the infamous rug, but I will say that it LITERALLY ties the room together...or in this context, our production environment.

CLR
There's actually a question for server names at serverfault. You could put this answer there too. http://serverfault.com/questions/45734/the-coolest-server-names
Matthew Crumley
A: 

I was writing a bejeweled clone, and I had functions for destroying (killing) and restoring (ressurecting) jewels from a pool. So I once wrote something like this:

Jewel* jesus = RessurectJew();
Kronikarz
A: 

It's just a comment but I couldn't help myself.

def this_is_recrawl(config):
    """SPARTAAAAAA"""

    if config.has_option("global", "recrawl"):
        return config.getboolean("global", "recrawl"):

    return False
Ted Dziuba
+3  A: 

In a debugging session with colleagues I said "set the break to 0xC0FFEE", meaning: "Let's go for a coffee break."

Rob
+3  A: 
abstract class Sex {

}

class SexWoMen  extends Sex {
   long duration;
}

class SexMen  extends Sex {
   byte duration;
}
fastcodejava
+1  A: 

Some code for sending emails

//Let's take care of the email body
StringBuilder bodyBuilder = new StringBuilder();
PieterG
+3  A: 

A collection of my favorites (I hope someone actually reads this):

/**
 * @file: getport.cpp
 * @author:
 */
// No wonder he didn't write his name above this crap. I wouldn't.

// If we can't divide by zero, we have to use something very similar:
m = v / 0.0000000000000000000000000000000000000000000000000000001;

// window destructor
Window::~Window() {
    // wait for the window to close, it's cold outside
    pthread_join(thread1, NULL);
    endwin();
}

Thread.Sleep(2000);
// This is for pure effect, the algorithm is so fast
// that no one would actually believe it

def AVeryCleverFunctionThatCalculatesIfTheNumberGivenByEntryWidgetIsReallyAPrimeNumberOrItIsDividableByAnotherNumberOtherThanFirstPlusNumberWhoseDistanceFromZeroIsEqualToOneOrByItself:

def parseRESData:
    # pornhub.com
    return FALSE;

Not even one of these is actually mine, but I consider them so freaking hilarious I have to share with you :-)

Jakub Lédl
I like the divide by nearly zero one...
Wayne Werner
How the hell did "def" get into C++? How the hell did `Thread.Sleep` get into C++?
Billy ONeal
It didn't. These are codeblocks from different languages (C++, Python, C#, the second can be anything), but this web text generator that Stack Overflow uses joined them all into single <pre class="prettyprint"></pre>.
Jakub Lédl
+1  A: 

I like to name objects and methods after religious and mythological entities. Examples:

// class for search engine
// St. Anthony of Padua is the Catholic patron saint of lost things
public class StAnthony

// destroy and reconstruct test db
void Shiva()  // Hindu god of destruction
void Brahma() // Hindu god of creation

// close the program
// Ousoos is a giant from Arabic mythology associated with clothes.
// Clothes <~> close
void Ousoos()
Dinah
**Please, NO!** I would hate to maintain your code.
SLaks
+1  A: 

Just for fun, I named one of my methods as such:

tell_the_user_that_the_program_has_like_totally_finished_doing_its_thang_by_calling_this_butt_long_method_name_man

Jesse J
+1  A: 

In a menu control i found the following comment

if (_isPage) // If you are a page, you are steril and can't have childrens
    HasChildren = false;
Anders Rask