359
votes

What is the best comment in source code you have ever encountered?

0

518 Answers 518

1
2
3 4 5
18
295
votes
double penetration; // ouch
3
  • 12
    Any good physics simulation will have a million double-entendres involving the word "penetration."
    – Charlie
    May 21, 2009 at 22:04
  • 21
    That's where it came from. The guy who wrote it started to chuckle (in the same room as me), then he added the comment. I suppose initializing it to DOUBLE_MAX would've been even funnier. :)
    – Macke
    May 22, 2009 at 9:56
  • 9
    The pun in "double"-entendre amuses me. Is that a thing? Sep 29, 2010 at 6:58
290
votes
/////////////////////////////////////// this is a well commented line
0
269
votes
// I don't know why I need this, but it stops the people being upside-down

x = -x;
7
  • 46
    classic! ... a prof once told me that if you are having trouble with your open gl code just try flipping signs. it was really good advice
    – luke
    Nov 22, 2008 at 21:45
  • 9
    Why would flipping x make the people stop being upside-down?
    – Michael Myers
    Mar 2, 2009 at 19:17
  • 10
    That's what made it the best comment -- it made no sense at all, and provided no good explanation as to why it worked :) Mar 10, 2009 at 17:25
  • 3
    @Michael Myers: it might be because he calculated y as the cross product of x and z.
    – Ergwun
    Jan 24, 2011 at 1:46
  • 1
    There is this software story that a software bug would cause the F16 to flip upside down when it crossed the equator ... Maybe this was the patch ... :-) Jul 20, 2011 at 17:00
254
votes

One of the most classic ones is the comment made by Pierre de Fermat about his well-known "Last theorem": "The margin of this page is a bit too small to write down the proof".

It took more than 350 years before the proof was found...

(According to wikipedia this is the original text:)

Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et generaliter nullam in infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet.

...and translated into English:

(It is impossible to separate a cube into two cubes, or a fourth power into two fourth powers, or in general, any power higher than the second into two like powers. I have discovered a truly marvellous proof of this, which this margin is too narrow to contain.)

21
  • 38
    It's interesting (to me at least) that the proof found 350 years later relied on mathematical techniques that were unavailable in Fermat's time, and was considerably longer than would fit in Fermat's margin. So, either he was mistaken, or there's a simple proof that remains a mystery.
    – Martin
    Oct 13, 2008 at 15:10
  • 13
    Maybe Fermat wasn't wrong. If he'd found a simple proof, it would have fit in his margin. Oct 14, 2008 at 6:25
  • 66
    John Skeet would have found room...
    – annakata
    Dec 1, 2008 at 17:24
  • 7
    Well, I read the (by the way great) book from Simon Singh about him: The guy was a writing a lot of things and said a lot of things without providing proof. Just as other attempted, he probably thought that he had found the proof, but it was also probably incorrect.
    – Roalt
    Dec 2, 2008 at 20:31
  • 43
    @annakata - and Jon Skeet would kill you for typing the name of his evil twin. Dec 10, 2008 at 0:38
254
votes
// I am not sure if we need this, but too scared to delete. 
7
  • 51
    Fairly sure i have written that one Oct 13, 2008 at 15:05
  • 21
    Story of my life. Aug 23, 2009 at 20:44
  • 8
    O my! Looks like someone needs to learn about Version Control. Jul 8, 2010 at 5:59
  • 1
    The comment reflects that the author does not know about the "If you don't fix it, it will break 100%" and the "Never run an unchanged system" rules. (Or what were those rules exactly?) :) Sep 1, 2010 at 13:23
  • That's why all my files never decrease in size!
    – Mike
    Sep 20, 2010 at 13:59
233
votes

From Java 1.2 SwingUtilities:

doRun.run();  // ... "a doo run run".
9
  • 8
    I guess I'm the only one who got the reference Mar 5, 2009 at 18:50
  • I laughed so hard reading this. Nice.
    – Jeff Yates
    Mar 5, 2009 at 19:42
  • 1
    Nice one, but lacks on run. Man, I even got that song in my head.
    – martiert
    Apr 3, 2009 at 16:14
  • 33
    youtube.com/watch?v=dqgtsai2aKY
    – Sprintstar
    Apr 6, 2009 at 10:59
  • 3
    It isn't exactly Swing, though...
    – sbi
    Sep 17, 2010 at 8:51
229
votes
# To understand recursion, see the bottom of this file 

At the bottom of the file:

# To understand recursion, see the top of this file
15
  • 57
    That's more like an infinite loop, there's no need for a stack with that example. Feb 2, 2009 at 21:04
  • 24
    How about "# To understand recursion, see line X" on line X?
    – Chris Lutz
    Feb 13, 2009 at 1:48
  • 30
    Good. But "To know what recursion is, you have to know what recursion is" is better :) Mar 10, 2009 at 15:15
  • 29
    When doing my A Level computing course we had a book, in the book the glossary contained two entries: Endless Loop - See 'Loop, Endless' ... Loop, Endless - See 'Endless Loop'
    – Piku
    Apr 19, 2009 at 21:46
  • 10
    To understand recursion, see this comment. BAM!
    – Randolpho
    Apr 24, 2009 at 19:37
223
votes

This one was a living proof, in production code, of micro-management effects in our team:

// I am not responsible of this code.
// They made me write it, against my will.

... followed by less than optimal code, conceived by our beloved technical director, who was quite fond of forcing down both code and coding guidelines into developers' throats (*).

Of course, when the project leader searched for the cause of a bug, and found it was inside the "less than optimal code", he was less than amused...

(*) I am, of course, mentioning the Mighty VB King... If you want to assess the full magnitude of the power of the Mighty VB King, you can read the following SO post: What was the strangest coding standard rule that you were forced to follow? ...

8
  • 35
    Your comment in the other posts links back to this one, sending me into an infinite loop for all eternity!
    – Tim Frey
    Jan 27, 2009 at 3:29
  • To understand recursion..... >: ) Mar 5, 2009 at 19:22
  • Absolutely wonderful, just imagine the plight the developer was under
    – Prabhu R
    Jul 21, 2009 at 11:09
  • 27
    @Outlaw: This is why I always open new links in separate tabs. Eventually I will get out of it, as my browser will crash.
    – T.E.D.
    Sep 17, 2009 at 16:12
  • A less obvious "Coactum feci" has saved many a soul.
    – relet
    Sep 16, 2010 at 17:44
219
votes

I went through a sleep-deprived coding run and started only writing comments that were quotes from Fight Club.

Still trawling through the code years later I find a comment that makes me laugh. Most of them just random thoughts. I did however keep my comments to lines ratio pretty good!

// This shouldn't happen. The only way this can happen is if the
// <code>JFileChooser</code> has returned a <code>File</code> that doesn't exist
// on the system. If this happens we can't recover, and there is more than likely
// a rip in the space time continuum that the user is too distracted by to notice
// anything else.

 /**
   * This method leverages collective synergy to drive "outside of the box"
   * thinking and formulate key objectives into a win-win game plan with a
   * quality-driven approach that focuses on empowering key players to drive-up
   * their core competencies and increase expectations with an all-around
   * initiative to drive down the bottom-line. I really wanted to work the word
   * "mandrolic" in there, but that word always makes me want to punch myself in
   * the face.
   */
private void updateFileCountLabel() {
10
  • 6
    Ah, now we know who writes those Spring Framework tutorials.
    – finnw
    Oct 10, 2008 at 2:51
  • 4
    The second one is just awesome. I always laugh when my wife uses the (non-)word "synergy" and she doesn't understand why it's so funny. Oct 21, 2008 at 19:46
  • 11
    The second one is great! What, no "paradigm-shifting"?
    – gnovice
    Jan 13, 2009 at 19:33
  • 37
    Just to be fair, the first clause might happen if in between the user selecting the File, the File disappears, which might in fact happen on a network file system. Assumptions like that have bitten me in the past...
    – Kirk Wylie
    Apr 19, 2009 at 20:31
  • 5
    We need to leverage exponential synergy curves to effect a paradigm shift in order to whitestream the knowledge gap through the data fusion engine.
    – user21037
    Apr 20, 2009 at 8:43
217
votes

Many years ago (about 1994) I was working on a Oracle PRO*C application for a large multi-national software company that you will have heard of. The app I was working on was a massive Oracle application and they had a utility that ran overnight tidying up data and doing all sorts of aggregate calculations. Every time anything needed doing as a batch job, it got shoved into this utility and as you can imagine it became an absolute monstrosity. It was also notable for the tiny number of comments that it had for such a massive program.

One of the few comments it did have remains the finest comment I have ever seen for pure WTF'ness... I was trying to find a bug in a function which was hundreds of lines long and right in the middle of it was the only comment in the function:

/* I did this the other way */

To this day it is still the finest comment I have ever seen.

5
  • 27
    I like that. it's enigmatic, yet useless. Oct 11, 2008 at 18:33
  • Indeed... mostly useless
    – Sakkle
    Feb 2, 2009 at 12:34
  • 3
    It makes me wonder if there was a disagreement about how to do something and the guy very smuggly declares that he decided to do it his way. LOL
    – AaronLS
    Apr 3, 2009 at 13:34
  • 3
    I read it as "there is a right way to do this, a wrong way to do this, and..."
    – Ry Jones
    Apr 4, 2009 at 18:09
  • +1 Excellent comment, and for "pure WTF'ness", a phrase that will starting showing up in my comments ;-)
    – Chris O
    Jul 28, 2010 at 1:43
216
votes
/* Please work */
5
  • 10
    I know the feeling :)
    – johnc
    Jan 23, 2009 at 11:02
  • 6
    i'll try this to see if it helps any... :D Apr 6, 2009 at 11:52
  • 235
    My boss tells me this whenever he sees me reading SO. Apr 20, 2009 at 20:10
  • 8
    @"My boss tells me this whenever he sees me reading SO.": OMG!!! I can't stop laughing!!! Apr 23, 2009 at 23:53
  • @Mike Miller i have been constantly checking around just to make sure that does not happen to me.
    – Jake
    Feb 7, 2011 at 6:22
212
votes
//Dear future me. Please forgive me. 
//I can't even begin to express how sorry I am.  

And I just found this one today:

//private instance variable for storing age
public static int age;
6
  • 3
    I'm always leaving comments for myself in the future... Apr 14, 2009 at 14:39
  • 26
    Future-self is who your comments should be written for anyway. Apr 20, 2009 at 10:50
  • In regards to the second comment, the programmer didn't explain what type of variable it is. Sloppy.
    – user43040
    Feb 13, 2010 at 9:05
  • 1
    @abrereton - obviousily it is a double, its bad form to put such redundant data in the comment
    – Felan
    Sep 21, 2010 at 17:14
  • 9
    Future-self hates me, and it's not even my fault. It's all Past-self's fault, damn him!! Sep 28, 2010 at 13:58
207
votes
/* You are not meant to understand this */ 
9
  • 13
    This is one of those Hofstadterian uses of "this".
    – harpo
    Oct 8, 2008 at 20:55
  • 10
    Very reminiscent of the infamous "you are not expected to understand this" comment in the UNIX source code: cm.bell-labs.com/who/dmr/odd.html Oct 10, 2008 at 0:33
  • It's hard to tell whether it's supposed to mean "This code is unreadable so don't feel bad if you dan't understand it" or "You won't understand my code because you're nowhere near as smart as me."
    – finnw
    Oct 10, 2008 at 2:56
  • "It's hard to tell whether it's supposed to mean..." -- In other words, it's hard for you to understand the comment. Which means it was one of those Hofstadterian uses of "this". Oct 14, 2008 at 6:20
  • 1
    In other words, "all bugs/defects should be directed my way. This is my means of securing my job."
    – icelava
    Dec 18, 2008 at 4:23
192
votes
//I am not sure why this works but it fixes the problem. 

This was before a set of code that technically did fix the problem it was meant to but broke 3 other things....

5
  • Classic case of this: pragprog.com/the-pragmatic-programmer/extracts/coincidence
    – ilitirit
    Oct 8, 2008 at 20:44
  • Yes it is. In fact most of this guys code fit that case. Lucky me gets to support it lol. Oct 9, 2008 at 14:06
  • 3
    except for the broking of three other things, ive done some comments like that Jan 31, 2010 at 18:53
  • lol. I have written this myself...
    – Layke
    Feb 21, 2010 at 19:27
  • I do that sometimes when I know from past experiance that 1 out of a few combinations will work, i just can't remember which one. trial and error can be done quickly when you are at a computer, sometimes it a lot quicker than redoing math for no reason.
    – Ape-inago
    Apr 9, 2010 at 5:02
186
votes
// no comments for you
// it was hard to write
// so it should be hard to read
4
  • 58
    They should have moved 'so it' to the previous line to make it a Haiku... Oct 23, 2009 at 12:32
  • 1
    I know company, where "head programer" has tesis: the code should be hard-readable, because noone should touch the code until he/she absolutely understand the code.
    – TcKs
    Sep 23, 2010 at 14:47
  • 2
    That's what I read between the lines of code I have to maintain... Dec 30, 2010 at 21:34
  • @TcK, head programmer just needs to be "new programmer" in a similar shop to see the error of his ways. Sep 17, 2011 at 9:28
178
votes
/* Halley's comment */
3
  • You can only use it once, but it's a good one! Oct 11, 2008 at 18:47
  • 38
    hahah brilliant. you only see one every 75 years, and the last one was in 1986.
    – nickf
    Oct 13, 2008 at 7:12
  • now that really is funny
    – Ian G
    Apr 6, 2009 at 11:44
178
votes
options.BatchSize = 300; //Madness? THIS IS SPARTA!
0
172
votes
// I have to find a better job
3
  • 16
    I'm feeling exactly that.
    – chakrit
    Nov 21, 2008 at 21:47
  • ha ha.... I have thought this way many times ;-)
    – Muhammedh
    Feb 10, 2010 at 6:38
  • 1
    Nice way to tell your boss about the same!
    – Raghav
    Jul 31, 2011 at 19:59
172
votes

Our DBA found this in the middle of a 3000 line stored procedure written by a third party.

/* IF DOLPHINS ARE SO SMART, HOW COME THEY LIVE IN IGLOOS? */
3
  • 12
    Page 3, and finally one makes me LOL.
    – tsilb
    Nov 20, 2009 at 3:43
  • 5
    It is from South Park.
    – Tgr
    May 31, 2010 at 10:11
  • 3000 lines? That's counter tons of codings styles/guidelines. And it's a stored proc?! Jun 30, 2011 at 18:06
171
votes

on js code:

// hack for ie browser (assuming that ie is a browser)
8
  • 69
    ie is not a browser, it's a monsturous html viewer that enjoys torturing web developers!
    – hasen
    Mar 16, 2009 at 11:07
  • 4
    but there are ever firefox/chrome/safari - better than a M$ product Apr 24, 2009 at 9:12
  • 1
    @Andrei Rinea: "I swear, honey, I've reformed myself. I'm totally different now." Although it might be true, I'm not inclined to believe it. Nov 26, 2009 at 17:14
  • 6
    IE8 is great until 2016 when it still has 15% marketshare
    – user132748
    Jun 25, 2010 at 15:48
  • 39
    "Internet Explorer: A simple Windows XP tool which allows the user to browse to Mozilla.com and download Firefox, a web browser." urbandictionary.com/… Oct 20, 2010 at 12:53
155
votes
/* Emits a 7-Hz tone for 10 seconds.
  True story: 7 Hz is the resonant frequency of a
  chicken's skull cavity. This was determined
  empirically in Australia, where a new factory
  generating 7-Hz tones was located too close to a
  chicken ranch: When the factory started up, all the
  chickens died.
  Your PC may not be able to emit a 7-Hz tone. */

main()
{
    sound(7);
    delay(10000);
    nosound();
}

(the sound function in the Turbo C version 2.0 Reference Guide)

8
  • 56
    You need a factory to create 7Hz tones? How do they package them, and what is their market?
    – johnc
    Mar 16, 2009 at 1:45
  • 2
    I read this comment in Turbo C a long time ago. It's amazing! Apr 20, 2009 at 1:03
  • 3
    It doesn't matter if it's true, its still just as funny. Maybe funnier. Can you imagine making it up? Apr 23, 2009 at 1:07
  • 4
    It simply can't be true. But it's hilarious that so many people believe an unsourced claim that ridiculous.
    – niXar
    May 21, 2009 at 15:58
  • 2
    Infrasound. See in particular the section by about Tandy's Ghost in the Machine.
    – Paul Ruane
    Sep 17, 2010 at 14:36
149
votes

... or die // bitch

1
  • 12
    I wasn't going to upvote, but it made me laugh, dammit
    – johnc
    Mar 26, 2009 at 23:00
147
votes

Try typing your favourite profanity into google code search, it whiles away many a dull hour. Some of my favourite examples:

/* These magic numbers are fucking stupid. */

/* Dear free software world, do you NOW see we are fucking
   things up?! This is insane! */

/* We will NOT put a fucking timestamp in the header here. Every
   time you put it back, I will come in and take it out again. */

# However, this only works if there are MULTIPLE checkboxes!
# The fucking JS DOM *changes* based on one or multiple boxes!?!?!
# Damn damn damn I hate the JavaScript DOM so damn much!!!!!!

/* TODO: this is obviously not right ... this whole fucking module
   sucks anyway */

/* FIXME: please god, when will the hurting stop? Thus function is so
   fucking broken it's not even funny. */

and my personal favourite

 # code below replaces code above - any problems?
 # yeah, it doesn't fucking work.
4
  • Just the linux kernel has got enough, mostly moaning about some crap hardware or other
    – Mark Baker
    Oct 9, 2008 at 9:03
  • Mmm, multiple checkboxes in JavaScript... I think I have a comment of my own like that.
    – scunliffe
    Dec 21, 2008 at 21:24
  • 14
    Posted HTML checkbox value handling is a WTF in its own right.
    – Rob Howard
    Apr 22, 2009 at 7:36
  • 3
    I love when people use checkboxes for an OR state rather then radio buttons which are built for purpose. Select insurance A OR B, ooo tick boxes Cue unnecessary javascript and making code fat. Feb 13, 2010 at 18:31
146
votes

On initialization of a linked list:

last = first; /* Biblical reference */

Succint and hilarious.

4
  • Biblical? More like Oedipeal. Sep 17, 2010 at 8:31
  • 16
    Biblical. Matthew 20:16 "So the last will be first, and the first will be last." (Not being a Bible nut, or even especially religious, I Googled it.) Sep 17, 2010 at 17:15
  • 9
    This is a job for Python's tuple packing/unpacking assignment: last, first = first, last Oct 8, 2010 at 20:39
  • @Brian for the times, they are a-changin'.
    – hobbs
    Aug 23, 2011 at 1:57
145
votes

Somebody complained that the "best" comment was bringing up the worst comments. IMHO, they're funnier, and so "better", but here's the honest best comment I've ever read:

/*
Major subtleties ahead:  Most hash schemes depend on having a "good" hash
function, in the sense of simulating randomness.  Python doesn't:  its most
important hash functions (for strings and ints) are very regular in common
cases:

>>> map(hash, (0, 1, 2, 3))
[0, 1, 2, 3]
>>> map(hash, ("namea", "nameb", "namec", "named"))
[-1658398457, -1658398460, -1658398459, -1658398462]
>>>

This isn't necessarily bad!  To the contrary, in a table of size 2**i, taking
the low-order i bits as the initial table index is extremely fast, and there
are no collisions at all for dicts indexed by a contiguous range of ints.
The same is approximately true when keys are "consecutive" strings.  So this
gives better-than-random behavior in common cases, and that's very desirable.

OTOH, when collisions occur, the tendency to fill contiguous slices of the
hash table makes a good collision resolution strategy crucial.  Taking only
the last i bits of the hash code is also vulnerable:  for example, consider
[i << 16 for i in range(20000)] as a set of keys.  Since ints are their own
hash codes, and this fits in a dict of size 2**15, the last 15 bits of every
hash code are all 0:  they *all* map to the same table index.

But catering to unusual cases should not slow the usual ones, so we just take
the last i bits anyway.  It's up to collision resolution to do the rest.  If
we *usually* find the key we're looking for on the first try (and, it turns
out, we usually do -- the table load factor is kept under 2/3, so the odds
are solidly in our favor), then it makes best sense to keep the initial index
computation dirt cheap.

The first half of collision resolution is to visit table indices via this
recurrence:

    j = ((5*j) + 1) mod 2**i

For any initial j in range(2**i), repeating that 2**i times generates each
int in range(2**i) exactly once (see any text on random-number generation for
proof).  By itself, this doesn't help much:  like linear probing (setting
j += 1, or j -= 1, on each loop trip), it scans the table entries in a fixed
order.  This would be bad, except that's not the only thing we do, and it's
actually *good* in the common cases where hash keys are consecutive.  In an
example that's really too small to make this entirely clear, for a table of
size 2**3 the order of indices is:

    0 -> 1 -> 6 -> 7 -> 4 -> 5 -> 2 -> 3 -> 0 [and here it's repeating]

If two things come in at index 5, the first place we look after is index 2,
not 6, so if another comes in at index 6 the collision at 5 didn't hurt it.
Linear probing is deadly in this case because there the fixed probe order
is the *same* as the order consecutive keys are likely to arrive.  But it's
extremely unlikely hash codes will follow a 5*j+1 recurrence by accident,
and certain that consecutive hash codes do not.

The other half of the strategy is to get the other bits of the hash code
into play.  This is done by initializing a (unsigned) vrbl "perturb" to the
full hash code, and changing the recurrence to:

    j = (5*j) + 1 + perturb;
    perturb >>= PERTURB_SHIFT;
    use j % 2**i as the next table index;

Now the probe sequence depends (eventually) on every bit in the hash code,
and the pseudo-scrambling property of recurring on 5*j+1 is more valuable,
because it quickly magnifies small differences in the bits that didn't affect
the initial index.  Note that because perturb is unsigned, if the recurrence
is executed often enough perturb eventually becomes and remains 0.  At that
point (very rarely reached) the recurrence is on (just) 5*j+1 again, and
that's certain to find an empty slot eventually (since it generates every int
in range(2**i), and we make sure there's always at least one empty slot).

Selecting a good value for PERTURB_SHIFT is a balancing act.  You want it
small so that the high bits of the hash code continue to affect the probe
sequence across iterations; but you want it large so that in really bad cases
the high-order hash bits have an effect on early iterations.  5 was "the
best" in minimizing total collisions across experiments Tim Peters ran (on
both normal and pathological cases), but 4 and 6 weren't significantly worse.

Historical:  Reimer Behrends contributed the idea of using a polynomial-based
approach, using repeated multiplication by x in GF(2**n) where an irreducible
polynomial for each table size was chosen such that x was a primitive root.
Christian Tismer later extended that to use division by x instead, as an
efficient way to get the high bits of the hash code into play.  This scheme
also gave excellent collision statistics, but was more expensive:  two
if-tests were required inside the loop; computing "the next" index took about
the same number of operations but without as much potential parallelism
(e.g., computing 5*j can go on at the same time as computing 1+perturb in the
above, and then shifting perturb can be done while the table index is being
masked); and the dictobject struct required a member to hold the table's
polynomial.  In Tim's experiments the current scheme ran faster, produced
equally good collision statistics, needed less code & used less memory.

Theoretical Python 2.5 headache:  hash codes are only C "long", but
sizeof(Py_ssize_t) > sizeof(long) may be possible.  In that case, and if a
dict is genuinely huge, then only the slots directly reachable via indexing
by a C long can be the first slot in a probe sequence.  The probe sequence
will still eventually reach every slot in the table, but the collision rate
on initial probes may be much higher than this scheme was designed for.
Getting a hash code as fat as Py_ssize_t is the only real cure.  But in
practice, this probably won't make a lick of difference for many years (at
which point everyone will have terabytes of RAM on 64-bit boxes).
*/
15
  • 4
    I'd heard of literate programming, but this is crazy. Great comment!
    – sep332
    Dec 19, 2008 at 16:11
  • 11
    Great comment, but IMHO one that doesn't really belong in the source but rather in an accompanying document. This is why document control is just as important as source control. Feb 9, 2009 at 8:52
  • 12
    I don't think this is user-level documentation, you should never need to know this when writing your code. Seems fine where it is to me.
    – llimllib
    Feb 10, 2009 at 20:58
  • 11
    A comment that explains exactly what was done and why. This is why Python is my favorite language.
    – cygil
    Mar 16, 2009 at 11:53
  • 55
    To commentators: If its a blog post or a separate document, it's NOT THERE when someone goes to modify the code. Having it in the code is the most convenient for future maintainers. And if the code is changed, there's a good chance the maintainer will update the comment; there's less chance a document or blog post would be changed (and if it was changed then you lose the docs for old versions; comments get versioned in the version control system with the code).
    – user9876
    Apr 20, 2009 at 12:50
128
votes
if(m_measures =/*=*/ --index)
{
    ....
11
  • 3
    That's... just insanely stupid and ASKING for trouble... Oct 12, 2008 at 4:56
  • 50
    Alternatively, like FALLTHRU, it's indicating that "this code which looks like a bug isn't" Oct 13, 2008 at 8:06
  • 4
    Yeah, better to just pull things apart a bit... Dec 15, 2008 at 15:43
  • 16
    Yet I'm strangely drawn to it ...
    – johnc
    Jan 23, 2009 at 11:01
  • 2
    No, you don't want to do it at all. :P
    – Robert P
    Mar 27, 2009 at 0:51
128
votes
int MyFunction()
{
    // There once was a man named Dave
    int Result = 0;

    // Whose code just wouldn't behave
    MyObject *Ptr = new MyObject();

    // He left to go to a meetin'
    Result = Ptr->DoSomething();

    // And left his memory a leakin'
    return Result;
}

C++ Comment

5
  • 7
    why not fix the leak instead?
    – hasen
    Dec 15, 2008 at 15:49
  • 82
    It's nice that, just as the memory is left leaking, the limerick is left unended. Dec 18, 2008 at 12:02
  • 49
    I hate meetings. Nov 14, 2009 at 0:18
  • 2
    @Adriano: Looks like something ending on "save" would be a good fifth line then...
    – Franz
    Aug 7, 2011 at 8:21
  • I need a 5th line, no resolution, ahhh!!! Nov 17, 2011 at 20:12
126
votes
/*
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
2
  • 4
    hillarious, this one made me choke up on my coffee :D! Apr 19, 2009 at 23:15
  • "but today is my last day" Beware company owners!
    – Raghav
    Jul 31, 2011 at 20:04
117
votes
  mov si, pCard      ; captain?
5
  • 1
    LOL! this one is good :D
    – Trap
    Mar 1, 2009 at 1:53
  • Need explainationsfor non assembler programmers Sep 14, 2009 at 14:23
  • 6
    @Clement No it doesn't. Read it out loud. Sep 22, 2009 at 19:57
  • @Jacob Move ship card Captain?? Sep 23, 2011 at 3:05
  • Here's a hint: pCard was portrayed by Patrick Stewart. Sep 25, 2011 at 1:25
109
votes
// I know the line below is wrong, but it came that way from our IP vendor, and 
// the driver won't work if you "fix" it. I've had to revert this change 4 times
// now. Leave it alone, or I will hunt you down and hurt you
if (r = 0) {
    /* bunch of code here */
}
else
{
   /* even more code here */
}
9
  • 3
    I just love this, it makes my heart smile that someone just couldn't stand leaving the line as it was. Classic.
    – Mia Clarke
    Apr 15, 2009 at 4:27
  • 5
    Wouldn't it be better to replace it with just r = 0; Apr 22, 2009 at 12:09
  • 20
    unless r is an object that overloads the = operator, and they grossly misused operator overloading.
    – user19302
    May 5, 2009 at 18:17
  • 8
    No C++ operator overload trickery here. The code in the "else" block handled the case of r==0 just fine. Presumably the intent of the original author was to do some special processing in the r==0 state. Since the code in the "if (r=0)" block never got executed, they eventually fixed it in the other block, leaving that useless code up at the top. Now, the guys who kept "fixing" it didn't have any reason to be modifying that code, and they certainly never tested the code after they changed it. Keeping the code exactly as we got it from the vendor made it easier to integrate future versions. May 8, 2009 at 5:26
  • 14
    That was clear, but (r =/*=*/ 0) is shorter. Jun 10, 2009 at 4:45
1
2
3 4 5
18

Not the answer you're looking for? Browse other questions tagged or ask your own question.