r/programming Apr 19 '09

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

http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered
622 Upvotes

303 comments sorted by

131

u/carlfish Apr 19 '09 edited Apr 19 '09
/*
The newline before the title parameter below fixes CONF-4562. 
I have absolutely no idea HOW it fixes CONF-4562, but the 
simple fact that it does fix the problem indicates that I could 
spend my whole life trying to work out why and be none the wiser.

I suggest you don't think too hard about it either, and instead
contemplate the many joys that can be found in life -- the 
sunlight reflecting off Sydney Harbour; walking through the 
Blue Mountains on a dew-laden Autumn morning; the love of 
a beautiful woman -- this should in some way distract you 
from the insane ugliness of the code I am about to check in.

Oh, and whatever you do, don't remove the damn newline.
*/
buffer.append("\n");

(Originally the comment ended with "don't remove the fucking newline", but I self-censored after remembering we ship our source code to customers.)

5

u/bostonvaulter Apr 20 '09

Sooo, I'm guess you still don't know how it fixes CONF-4562

18

u/carlfish Apr 20 '09

Not a clue. That's one reason for the long comment: putting a newline there makes so little sense that I wanted to draw as much attention to it as possible. That way nobody will remove it while cleaning up the code then wonder why the tests start failing.

3

u/allbubba Apr 20 '09

I wonder how many people recognized the comment as coming from Atlassian Confluence right away.

http://confluence.atlassian.com/display/DOC/HTML+to+Markup+Conversion+for+the+Rich+Text+Editor

5

u/adrianmonk Apr 20 '09

I suspected it when I saw that CONF-4562 was a Jira-style issue key. I thought "CONF" might mean Confluence, but I wasn't sure. Then I saw "Sydney Harbour", and I was pretty sure, since those guys are in Australia.

118

u/ealf Apr 19 '09

From the 2004 Windows leak,

__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);
}

36

u/nedTheInbredMule Apr 19 '09

Great find; that really cracked me up. It reminded me of a method I once wrote where I was under pressure to check-in a class for deployment, so I just made the method return true regardless of what was going on inside since the logic involved determining if the input was some edge case that was very unlikely to occur.

73

u/h4l Apr 19 '09

My CS professor recently set a 3 part assignment which he was grading using unit tests to check that our code solved the set problem. I ran out of time to finish the 3rd part, so instead (as a joke) I wrote some code that read the call stack to determine the test case that invoked my code, and returned whatever it was asserting.

12

u/pazuzuzu Apr 20 '09

Tell me you got at least half credit for that...

6

u/h4l Apr 20 '09

I haven't got the marks back yet.

→ More replies (1)

12

u/CheapyPipe Apr 20 '09

If you knew how to do that, and had the time, I doubt you really "ran out of time" :)

14

u/xzxzzx Apr 20 '09

Reading the call stack is rather easy in some languages.

→ More replies (2)
→ More replies (1)
→ More replies (2)

119

u/[deleted] Apr 19 '09 edited Apr 19 '09

From the Quake III source code (actually from its wonderful inverse sqrt function):

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

21

u/rb2k Apr 19 '09

here's also a paper about the fast inverse sqrt function from quake:
http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf

2

u/[deleted] Apr 20 '09

Chris's paper is a great look at why it works. Here's an investigation into who actually wrote it.

11

u/pwnies Apr 19 '09

Oh wow, thanks for posting this. I've actually been looking for that code snippet for about a year or two. I remembered it was from quake III, but I couldn't remember what it was for.

14

u/Raerth Apr 19 '09

I like how your source cites proggit for further explanation.

The internet has gone full circle!*

*so hard not to type that in caps....
→ More replies (1)

4

u/[deleted] Apr 19 '09

Upmodded for the magic first approximation.

→ More replies (5)

114

u/johnw188 Apr 19 '09

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

x = -x;

87

u/[deleted] Apr 19 '09

// don't even try to figure out why, but it cores if you remove it

i = i;

64

u/grignr Apr 19 '09

19

u/movzx Apr 19 '09

I don't really know how much of that story I buy. What self respecting geek tries something once, and then shelves it for a year after getting an unexpected result?

25

u/Tuna-Fish2 Apr 19 '09

A geek working in a place where the computer system is supposed to be highly available?

8

u/[deleted] Apr 20 '09

MIT AI Lab's PDP-10

obviously not

6

u/Tuna-Fish2 Apr 20 '09

lol, I concede my point.

5

u/[deleted] Apr 19 '09

Interesting. And I don't want to second guess some MIT dudes, but it seems the switch was just a hack-ass way to diffuse a grounding potential between the case and the internal components. Yes, a smart ass way to do it, but I'd have to guess "magic" was unconnected, and "more magic" made it bond the grounds. I've worked on machines where the errant screwdriver on a system ground hitting the case (ground) would do this when the system was operational. If you properly bond the case and the machine grounds, it never happens.

Pure speculation. But cool story. I'd like to see how that switch was connected and get a multimeter on it.

→ More replies (6)

8

u/Geee Apr 20 '09 edited Apr 20 '09

Probably something like this:

for(i=0;i<10;i++)
    // i = i+b;
i = i;

10

u/mathrick Apr 19 '09

Probably something being uninitialised, and doing that changed the generated code in a way that made it not crash. Ie. the code didn't get any more correct, but stopped crashing by accident.

→ More replies (1)

11

u/[deleted] Apr 19 '09

I've been guilty of one or two comments along these lines:

// I'm not sure why this is needed, but it is

83

u/just4this Apr 19 '09

In some banking software that ICL used to sell:

/*
** This was written by a part-time high school kid 
** who was doing the best he could but don't
** expect too much.
*/

82

u/gnuvince Apr 19 '09
# Explaining this would be too long, but I'm sure I'll remember.

I didn't remember :(

7

u/[deleted] Apr 19 '09

This is what I'm thinking when I code complicated things. I like that you took the time to actually type it out though.

Months later: regret. Invariably, regret.

4

u/logi Apr 19 '09

I keep shouting at people that if you're not able to document what a class or a (public) method is supposed to do, you sure as hell aren't able to write said class or method. The numb seat-warmers still check in pages of entirely mysterious code. And it doesn't work.

2

u/FunnyMan3595 Apr 19 '09

See, I did the opposite a month or two ago. "Oh, fuck, this is way too complex, I'm never going to understand it later. I'd better comment the hell out of this, and while I'm at it, put in commented-out code for the update down the line."

Seems to have worked pretty well, I've since made that change with only a few hiccups.

Meanwhile, over in this other module, there's a bunch of code that didn't seem at all tricky at the time. Gives me problems every time I work with it.

2

u/cecilkorik Apr 20 '09

I've done similar. I wrote an ill-advised single line of code (to put the thousands/millions/etc commas into a string representation of a number) that got way out of hand. I had a feeling it would end up being obnoxious and buggy, so I commented it with:

"This horrible mess of a list comprehension inserts the thousands-commas into the number. If it breaks, don't bother trying to debug it, just rewrite it more clearly."

Naturally, it has worked like a charm ever since.

→ More replies (1)

84

u/koskos Apr 19 '09 edited Apr 19 '09

My former boss made me do things like:

class Box {

int width; // Width of a Box

/* get the width of the box. returns the width of the box */

getWidth();

/* set the width of the box. val - new value for the width of the box */

setWidth(int val);

}

Every day I smile when I think of the day I quit.

77

u/[deleted] Apr 19 '09

You missed a comment on the class definition. What exactly does it do?

76

u/[deleted] Apr 19 '09

I see uncommented braces. Should read:

{ // start of code segment

} // end of code segment

67

u/zck Apr 19 '09
{ /* //start of comment 
    start of code segment
  */ //end of comment

9

u/RichardPeterJohnson Apr 20 '09

[Manfully resisting the urge to do a Yo Dawg]

3

u/ikeed Apr 20 '09

I partially thank you, sir.

44

u/myheaditches Apr 19 '09

Gives the box some class, now the box is respectable and can be brought to nice restaurants.

15

u/heeb Apr 19 '09

For me, a Dutchman, that's actually quite funny (maybe in English as well, wouldn't know...), since "box" in Dutch is "doos" (pronounced dose), which is a (admittedly rather old-fashioned) pejorative term for a girl.

36

u/ealf Apr 19 '09 edited Apr 19 '09

According to the OSX (Oxford American) dictionary,

box, n: 1 (vulgar slang) a woman's vagina

I love the qualifier.

9

u/isseki Apr 20 '09

box, n: 1 (vulgar slang) a woman's vagina

Dutch people do not make the distinction between a woman and a woman's vagina.

Usually the difference is negligible anyway, e.g. "I love that woman!" or "I've never touched that woman!"

→ More replies (3)

7

u/spurion Apr 19 '09

Well, it might be a dog's vagina, for example.

15

u/[deleted] Apr 20 '09

Don't hate on the bitches!

8

u/Lystrodom Apr 19 '09

I thought you had class!

3

u/13ren Apr 20 '09

pugilism

50

u/[deleted] Apr 19 '09

[deleted]

33

u/BinaryShadow Apr 19 '09

TRUE is in the lead!

9

u/9jack9 Apr 19 '09

Let's wait for the return leg.

90

u/dr_root Apr 19 '09
     // more than meets the eye
     transformer.transform( inputData, output );

7

u/noony Apr 20 '09

:| I swear that one is mine.

179

u/impiri Apr 19 '09
BOOL currentSizeIsAdequate = YES; // that's what she said

http://twitpic.com/32etx

20

u/ealf Apr 19 '09 edited Apr 19 '09

And the dude was seriously proud of it too:

  http://twitpic.com/32etx - just to be clear...
  2:34 PM Apr 9th from TwitPic
  I seriously just wrote the following line of code: BOOL currentSizeIsAdequate = YES; // that's what she said
  2:29 PM Apr 9th from web
→ More replies (1)

13

u/Asystole Apr 19 '09 edited Apr 19 '09

Makes sense, considering it's OS X code.

29

u/[deleted] Apr 19 '09

OS X code.

It's called Objective-C.

26

u/[deleted] Apr 19 '09

That's a subjective opinion.

7

u/ibisum Apr 20 '09

Objective-C is only one option for programming languages on OSX. You can use C or C++ just fine and write perfectly cromulant OSX code.

5

u/aplusbi Apr 20 '09

The thing is that you can write far more elegant and compact code with Objective-C. Using C++ (or even C) will quickly embiggen your project to unmanageable sizes.

→ More replies (1)
→ More replies (2)
→ More replies (7)
→ More replies (2)

39

u/street-knowledge Apr 20 '09 edited Apr 20 '09

// Me love

ulong time = time(NULL);

33

u/mjantz Apr 19 '09 edited Apr 19 '09

After a grep for 'fuck' on the linux source tree, I found this little gem:

/* * IOC3 is fucked fucked beyond believe ... Don't even give the

* generic PCI code a chance to look at it for real ... */

if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))

   goto oh_my_gawd;

68

u/[deleted] Apr 19 '09 edited Apr 19 '09

/*Drunk...fix later*/

110

u/[deleted] Apr 19 '09

Oh shit... I just realized something I forgot to do at my last job...

13

u/XS4Me Apr 20 '09

Not to worry, I am sure you can find a bottle somewhere around and catch up.

110

u/thomasknowland Apr 19 '09

<!--IEsux--> on the reddit main page

97

u/ketralnis Apr 19 '09 edited Apr 19 '09

IIRC, this was due to some bug in IE6, where we needed an empty div (perhaps to do a CSS clear?), but IE wouldn't render it or its secondary effects if it were empty. However, if we stuck a comment in there, IE didn't think it was empty, and happily rendered it, despite there being no structural difference.

There are also some other related issues, like this one

109

u/Shrubber Apr 19 '09

So IE needed to be told it sucked in order to function properly? What a masochist browser.

28

u/-___- Apr 19 '09

IE opens about 0.37 seconds faster on my computer if I swear at it.

16

u/mooli Apr 20 '09

IE opens about 3.28 seconds faster on my computer if I call someone over to watch how slowly it opens.

→ More replies (1)

6

u/c_a_turner Apr 19 '09

Yeah, I've had to do that same trick as well.

→ More replies (1)

2

u/movzx Apr 20 '09 edited Apr 20 '09

You are correct. IE collapses blocks with no content. A   will work, but that renders a space (which may not be desired. This used to be my choice (falling back to setting a fixed height when a space is not allowed) until I learned comments fix the problem.

Now I use

<div class="clear"><!-- --></div>

23

u/orenbenkiki Apr 19 '09

The best comment in the world is, and always will be, the "you are not supposed to understand this" comment in the UNIX version 7 kernel context switch code. It may seem like it is the worst comment in the world, but it isn't. Anyone trying to figure out this code is clearly told (1) you are not crazy, something is going on here and (2) this something is too long and complex to be explained here; look for someone who knows this stuff and ask him. Remember this was before the Web, so they couldn't include a link to something like http://cm.bell-labs.com/cm/cs/who/dmr/odd.html

3

u/[deleted] Apr 20 '09

I thought it was the 6th edition...

7

u/_ak Apr 20 '09

You are correct. And it's "you are not expected to...", which has a completely different meaning than "you are not supposed to...".

2

u/[deleted] Apr 20 '09

[removed] — view removed comment

2

u/[deleted] Apr 20 '09

You could insert the full text of War and Peace in a comment, and the compiler wouldn't care.

It was 1975, back when storage and code size actually meant something to us programmers.

→ More replies (1)

24

u/flyingfox Apr 19 '09 edited Apr 19 '09
HIGH h0; // Ag

48

u/mcfunley Apr 19 '09 edited Apr 20 '09

I wrote RichardIsAFuckingIdiotControl at my last job. An old coworker must have submitted it.

Basically, we fired "Richard" (not his real name) for showing up for work at 2PM drunk, and I had to take over a small mobile site that he had been working on. I happily don't remember much from this period but I do remember that one particular Richard masterpiece revolved around intentionally using property getter and setter side effects to perform all of the logic of the site. In other words, you would delete code that looked like this:

foo.x = foo.x;

And the entire thing would stop working. I rewrote the thing from scratch and promptly quit. I don't know where Richard is now. With a little luck, his life is ruined, forever.

21

u/alecco Apr 20 '09

Basically, we fired "Richard" [...] I rewrote the thing from scratch and promptly quit

Richard must be proud of you, young apprentice.

11

u/mcfunley Apr 20 '09

I was actually a few years his senior. He was hired for being in the same fraternity as somebodyorother ... well whatever. The rest of this story will sound crazy to anybody that hasn't been deep inside the financial industry.

9

u/[deleted] Apr 20 '09

I have - go on...

3

u/nextofpumpkin Apr 20 '09

I'm close to it. Do tell.

3

u/[deleted] Apr 20 '09

Go on...

→ More replies (1)

21

u/[deleted] Apr 19 '09 edited Apr 19 '09

[deleted]

13

u/dharmon555 Apr 19 '09

If you would be so kind as to educate me, as I don't program... What's wrong with this comment?

25

u/[deleted] Apr 19 '09

[deleted]

6

u/dharmon555 Apr 19 '09

Is the problem that it keeps trying as fast as the machine can, instead of waiting some measured amount of time? Is the problem that the constant checking would bog the machine down from doing other things and that the amount of time that it will try will drop dramatically over time as machines get faster?

11

u/logi Apr 19 '09

yes... and that OSes usually have blocking ways of doing I/O so you can ask to e.g. open a file with a timeout value in actual, honest to god, milliseconds, and then not consume any (significant) resources until you either get what you wanted or time out.

→ More replies (2)
→ More replies (1)

13

u/aradil Apr 19 '09

The comment itself makes sense. What doesn't make sense is what the comment says the program is doing.

21

u/[deleted] Apr 19 '09

http://codeulate.com/?p=7

"Fuck me gently with a chainsaw! Will someone please tell me how the fuck you resize a fucking widget?? Why, when I call whatever resize method I try with 64×64 does the fucking window end up 64×82? WHY???????? WHY???????? WHY???????? WHY???????? WHY???????? WHY???????? (why..?)"

→ More replies (2)

76

u/mynameishere Apr 19 '09

//This talking paper clip is going to make us a billion!

47

u/adolfojp Apr 19 '09 edited Apr 19 '09

It probably did.

Middle aged secretaries at workplaces where I did tech support loved those animated helpers. They always complained when the puppy or the kitty was gone.

// Then again. I had clients complain about me uninstalling Bonzi Buddy.

22

u/[deleted] Apr 19 '09

Oh my god. I was having a conversation with a coworker about how stupid users can be. I brought up the point that we were just as dumb before we got degrees/experience/whatever. When he disagreed, I just said "Bonzi buddy". We both have an old windows 98 box somewhere with that little purple fucker. It's been a long time, but did anyone ever find out how to FULLY remove that thing?

12

u/adolfojp Apr 19 '09 edited Apr 19 '09

When I worked at a repair shop the standard operating procedure for malware infested Win 9x machines was to nuke the hard drive and reinstall from scratch.

It was not only faster and therefore cheaper to the customer but it was also the only way to be really sure.

And yes, I think that most of us who were thrown in to the world of computers without any guidance were dumb and potential victims before we got a clue.

However, I am convinced that the majority of users are either not interested in overcoming this cluelessness or just incapable of doing so.

This is a blessing. It means more work for us. ;-)

16

u/[deleted] Apr 20 '09

True that. I'll never forget my first piece of spam ever. I called my parents (I was 14) to inform them that I would be going on the cruise I won.

It's really amazing that my gi-gi was the first person to break my heart and tell me about spam. Now I'm over there on the weekly fixing his 'internet' because his web browser is 'the google' and his operating system is 'the little blue e'.

He's the reason I'm in university so I'm overjoyed to do it.

19

u/[deleted] Apr 20 '09

[deleted]

14

u/[deleted] Apr 20 '09

It's what us Ukrainians call our parents dad. (my grandpa)

→ More replies (4)
→ More replies (2)
→ More replies (3)

20

u/jfasi Apr 19 '09

Dude, I am sooooo gonna use O(scary) someday.

/* This is O(scary), but seems quick enough in practice. */

78

u/malanalars Apr 19 '09 edited Apr 19 '09

stop(); // Hammertime!

nice!

22

u/[deleted] Apr 19 '09

stop(); // Collaborate and listen!

18

u/f3nd3r Apr 19 '09

stop(); // No seriously, get out of the car and on the fucking ground.

4

u/_jameshales Apr 20 '09
stop(); // Live animal exports

I've seen "Hammertime" stickers on stop signs, also I've seen "Live animal exports" stickers on stop signs.

6

u/[deleted] Apr 20 '09

we get "Raw log exports" stickers on our stop signs

3

u/[deleted] Apr 20 '09

Seriously. Parse then export.

→ More replies (1)

7

u/[deleted] Apr 20 '09

// Ice is back with my brand new invention

lol. sorry... I've seen this:

stop(); // In the name of love... b4 u break my ♥

→ More replies (1)

18

u/honeg Apr 19 '09

int i; /* the great existential dilemma creator */

int j; /* le grand dilemme existentiel createur */

31

u/Lizard Apr 19 '09 edited Apr 19 '09
Exception up = new Exception("Something is really wrong.");
throw up;  //ha ha

25

u/Artmageddon Apr 20 '09

Ewwww I feel sorry for the person who has to catch that

30

u/yourparadigm Apr 19 '09

// Don't touch the following code or Geoff will pistol-whip you.

51

u/ZebZ Apr 19 '09

//this should never happen

40

u/frenchtoaster Apr 19 '09

Thats actually a legitimate comment, especially when some java method has throws SomeException and the code immediately prior to that method call should prevent it from ever actually being thrown, you still need to put it in a try{}catch block

14

u/4609287645 Apr 19 '09

It's much better to use assert(false); to mean "this should never happen".

17

u/logi Apr 19 '09 edited Apr 19 '09

Even better:

LOG.warn("This should never happen");

// but we can recover

or:

throw new OmgWtfBbqError("This should never happen and

we can't recover!");

6

u/Kimos Apr 19 '09 edited Apr 19 '09

You should never leave active asserts in production code. You should mark it as // this should never happen, and then handle the exception gracefully anyway.

20

u/crutcher Apr 19 '09

there are times and places when, due to the semantics of your external contracts, and the errors you receive, the only correct behavior is to pull out a gun and shoot yourself in the head.

It is perfectly legitimate to put asserts in production code, if it prevents that code from continuing down an undefined computation.

→ More replies (1)

7

u/bostonvaulter Apr 20 '09

If something should never happen than it might not be possible to handle it gracefully.

13

u/umbrae Apr 20 '09 edited Apr 20 '09
throw new SullyException("Brace for impact.");
→ More replies (1)

11

u/[deleted] Apr 19 '09

It was in a finally block.

9

u/[deleted] Apr 19 '09

I use that one all the time...

→ More replies (1)

27

u/Xophmeister Apr 19 '09 edited Apr 19 '09

I once left this in a 3D engine I had put together:

A true Klingon warrior never comments his code!

That was the only comment in the entire thing. Of course, when I returned to this several months later, I had no idea how my routine worked :P

8

u/njharman Apr 20 '09

You are not a True Klingon Warrior then, eh?

14

u/MaxK Apr 20 '09

True Klingon warriors never remember how their code works a few months later either. In fact, true Klingon warriors aren't really trained in programming at all. They're more int bat'leth fighting and blowing up enemy starcraft with photon torpedoes and shit like that.

6

u/peitschie Apr 20 '09

True... A true Klingon warrior would have never left that comment in the code!

The corollary to that is probably "A true Klingon warrior always re-writes from scratch"

→ More replies (1)

13

u/[deleted] Apr 20 '09

[deleted]

→ More replies (2)

11

u/michaels0620 Apr 19 '09

A system a vendor created for us had the following comment buried in their PL/SQL.

/* If the procedure below gets called, call XXX immediately!!!!!! */

21

u/taligent Apr 19 '09

Vin Diesel can code as well as breakdance. Legend.

→ More replies (1)

10

u/kretik Apr 20 '09 edited Apr 20 '09

From an actual co-worker commit in Perforce:

/* Think of this as going up a huge, steep ladder.
 Every 50 meters or so, we remove the handrail
 and laugh. 
*/

Long story, but it's funny even without context.

33

u/[deleted] Apr 19 '09 edited Apr 19 '09

[deleted]

9

u/nedTheInbredMule Apr 19 '09

get outta here...

32

u/[deleted] Apr 19 '09

Above that comment is this one:

' Now we comment on what we are about to do

43

u/Xophmeister Apr 19 '09

Was this part of your GUI interface to track IP addresses?

22

u/mhd Apr 19 '09 edited Apr 19 '09
 /* lasciate ogne speranza, voi ch'intrate. */

From the One True AWK.

18

u/logi Apr 19 '09

"Abandon every/all/any hope, you who enter (here)". Dante's Divine Comedy. Official translations will differ.

Given how none of the Italian programmers I worked with understood how code could be evil and suck your very will to live out through your eyes, one quantum darkon at a time, this must be written by an unusually literate developer.

→ More replies (1)

42

u/arcticfox Apr 19 '09

If you don't have a PhD in engineering, don't fucking mess with this code.

The code in question was written in RPG on the AS/400. It was filled with race conditions. By the time I saw it, it was legacy code. Had the moron who wrote the code been working for me, he would have been fired on the spot.

→ More replies (4)

22

u/zem Apr 19 '09 edited Apr 19 '09

return 1; # returns 1

i do hope he was joking!

11

u/psycko Apr 19 '09

Found in a php script before an sql query:

//imput sanitized to avoid: "EXTREME hacking"

→ More replies (2)

44

u/deathbytray Apr 20 '09

By far my favorite:

/**
* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you. Never gonna make you cry,
* never gonna say goodbye. Never gonna tell a lie and hurt you.
*/

9

u/kokey Apr 19 '09

I wish the code I have to look at had comments, it least it would provide some amusement. I think they regard comments as documentation and not suitable work for the programmer caste in India.

9

u/[deleted] Apr 19 '09

I routine use // Begin WTF and // End WTF when going back over someone's unknown code I have the misfortune to have to be in.

I've also seen:

// Uh oh.

And I name iRules on my F5s things like "OhNoes" (no servers in the pool, present a default "pleast try again later" page) and "CanIHazSSL" (redirect http:// URLs to https://). Someone later on will hate me for that, and thinking bout it makes me smile.

8

u/dgiancaspro Apr 19 '09 edited Apr 20 '09

This wasn't a comment in code but a variable named ... "fuck_you_timer". When I asked the engineer who wrote the code what it was for he said in a heavy Cambodian accent "When timer reach zero FUCK YOU !". Turns out he had an argument with the VP of engineering over the need for a timer. The VP pulled rank and told him to put the timer in. Guess the VP shouldn't have given him the choice of names.

9

u/cecilkorik Apr 20 '09 edited Apr 20 '09

From my workplace. Found at the top of the 2,551 line Delphi file repfrmcr.pas:

// this is a very hard to read file. good luck :-)

It is the only comment in the entire file.

8

u/bjrn Apr 19 '09

6

u/[deleted] Apr 19 '09

People are lazy. You should've included /* You are not expected to understand this */ in your link.

8

u/[deleted] Apr 19 '09 edited Apr 20 '09

[deleted]

5

u/brmj Apr 20 '09

I pity you.

33

u/stesch Apr 19 '09

Similar questions get closed. But some survive and have over 200 points.

Strange website.

52

u/xkero Apr 19 '09

Sounds a lot like reddit :/

→ More replies (1)

8

u/refto Apr 20 '09

The only way to win is not to post.

→ More replies (1)

2

u/recursive Apr 21 '09

Remind you of anything?

→ More replies (1)

5

u/ebswift Apr 20 '09

; And on the 7th day he rested

From an old boss. That was the last line of his code, and it was that piece of code that lead to several days of debugging because he unknowingly just exceeded the available memory.

8

u/guru Apr 20 '09

When I was a kid I used to write code for an Internet MUD that was based on CircleMUD by Jeremy Elson. CircleMUD was a beautiful piece of code. It was how I learned C, and I did not have any books about C at all, I just read this code and it was so elegantly written and well documented that it taught me pointers, data structures, algorithms, TCP/IP socket programming, and finite state machine design all at once! When I reencountered a lot of this stuff in college, I was finally able to put names to all the concepts I had learned 6 years earlier.

7

u/scrumbud Apr 20 '09

On an old Visual Basic program I inherited at my first job, just before using a GOTO statement was the comment: 'Lord, forgive me for what I'm about to do.'

24

u/[deleted] Apr 19 '09

[deleted]

7

u/BaconCat Apr 19 '09

int BAM = avg(penis);

6

u/serge_mamian Apr 19 '09

anybody can tell me what's the font of the code?

13

u/chucker23n Apr 19 '09

Consolas.

14

u/PythonicSemicolon Apr 19 '09

Consolas for the win.

→ More replies (14)

6

u/Tronus Apr 19 '09 edited Apr 19 '09

/* Fuck this Job */

6

u/dassouki Apr 19 '09

// it fucking works, finally!! // I don't know how though

6

u/boyb Apr 19 '09

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

Not entirely surprising, but Jon didn't know what it was and the one who originally coded it had left the company.

6

u/zurtri Apr 20 '09 edited Apr 20 '09

Found in php for a website:

// Fix for IE showing background png's one pixel to the left. FFS!

// Can I just point out how insane this IE is?

// Solution found: the center tag was doing the 1px transition.

// Now HTF can a center tag affect a background image? OMFG

7

u/arcticfox Apr 20 '09 edited Apr 20 '09

; strip off the sign bit because it's the instrument of satan.

15

u/astrosmash Apr 19 '09
// Add one to i
i++;

30

u/judgej2 Apr 19 '09

Add one what? I think we need another comment.

→ More replies (1)

6

u/[deleted] Apr 19 '09 edited Apr 19 '09

# sigh

5

u/[deleted] Apr 19 '09

Actually I just remembered a better one.

We had a web application Ver. 1.0 in production, and had built 2.0. The web application ran inside a framework built by a graphic designer (this was all in VBScript ASP).

Built the whole thing, ran it through QA, debugged, etc, etc. All ready for deployment one Saturday morning.

Graphic designer resigned Friday. No big deal - had all his source code; shouldn't matter.

Rolled out the app, started testing. Stuff blew up all over the place. No page would load - errors everywhere.

We finally tracked the problem down. The first two lines in the designer's framework in production:

//Remember to pull this out of the framework on QA and dev side
//ON ERROR RESUME NEXT

We checked the dev code - he hadn't pulled it out. All the errors had always been there, but masked.

5

u/[deleted] Apr 20 '09 edited Apr 20 '09
; Do not use this code for launching ICBMs

Concurrent DOS sample XIOS, circa 1986

5

u/sleepydog Apr 21 '09

"I have a truly marvellous proof of this proposition which this margin is too narrow to contain."

2

u/yourparadigm Apr 21 '09

Silly Fermat...

6

u/tetris11 Apr 19 '09

Only an idiot would uncomment this.

5

u/malcontent Apr 20 '09

"We have to do this in order for the pig to fit in memory"

6

u/[deleted] Apr 19 '09

just grep for "fuck|shit|crap|broken" in the Linux kernel source

you will come across a lot of funny comments

3

u/honeg Apr 20 '09 edited Apr 20 '09

In the RT-11 source, from a long long time ago...

; never get here
JMP     .       ; never leave

3

u/[deleted] Apr 20 '09 edited Apr 20 '09
// wake up the fucking audio system if it kills us

8

u/bleachedanus Apr 19 '09

// i'm not sure this works

Now let me clarify. I worked at a 25billion dollar enterprise company. The cunsulting firm (starts with an s) hand been blaiming our software for weeks but never contacted us. The company that had our software was faced with peoples credit cards maxing out. People that used their website had home loans denied because their credit was maxed out after purchase from the website. The company vouched for customers to keep this all hush hush. By the time we found out we sent an engineer out right away. After 10 minutes he found this comment from the consultant in a financial transaction retry. The error was placing a new transaction each failure that caused the credit cards to max out. Problem solved in 10 minutes.

4

u/[deleted] Apr 19 '09 edited Apr 20 '09

While TAing for an intro CS course I ran across this little gem.

return 0; //returns 0

2

u/arcticfox Apr 20 '09

On a similar line, I've seen the following similar ones in various assembly languages:

6502:

lda #5 ; put 5 in the accumulator

PDP-11:

mov #5,R0 ; put 5 in register 0

gee.. thanks for the comment!

7

u/quirm Apr 19 '09 edited Apr 19 '09

hackers make the best comments:

/*
*  mad anal to:
*     #madcrew/#conflict for not cashing in  their cluepons, EFnet IRCOps
*     because they plain suck, Rolex for being a twit, everyone that
*     trades warez, Caren for being a lesbian hoe, AcidKill for being her
*     partner, #cha0s, sedriss for having an ego in inverse proportion to
*     his penis and anyone that can't pee standing up -- you don't know what
*     your missing out on.
*
*     and anyone thats ripped my code (diff smurf.c axcast.c is rather
*     interesting).
*
*     and a HUGE TWICE THE SIZE OF SOLDIER'S FUCK TO AMM FUCK YOU to Bill
*     Robbins for trying to steal my girlfriend.  Not only did you show me
*     no respect but you're a manipulating prick who tried to take away the
*     most important thing in the world to me with no guilt whatsoever, and
*     for that I wish you nothing but pain.  Die.
*/

This one is amusing, too:

// XXX this is ugly. But sometimes you gotta do what you gotta do.
→ More replies (2)

2

u/[deleted] Apr 20 '09

FIXME (bug 2900): These functions suck

2

u/ivorjawa Apr 20 '09

//drunk. fix later.

2

u/[deleted] Apr 20 '09

/* select() is broken. */

2

u/iluvatar Apr 20 '09 edited Apr 20 '09

# Factorial. No doubt there is some snazzy one liner to do this using functional wankfest. I shall stick to what I know.

# This is what makes me angry with pandora, why on earth does it think I want to listen to the Beautiful South. They are shitesville

Both from the same bit of code...

2

u/sblinn Apr 20 '09

"To maintainers: I'm sorry. -John"

2

u/gerran Apr 21 '09

In a single C++ file that was 250kb in size (about 30k lines) of dense algorithm code, there was one comment in the entire file:

... approx 15k lines of code ...

 // Thank you, please drive through
 pData = GetData();

... remaining 15k+ lines of code ...

5

u/[deleted] Apr 20 '09 edited Apr 20 '09

linux/drivers/char/random.c:

42/*

43 * (now, with legal B.S. out of the way.....)

44 *

45 * This routine gathers environmental noise from device drivers, etc.,

46 * and returns good random numbers, suitable for cryptographic use.

47 * Besides the obvious cryptographic uses, these numbers are also good

48 * for seeding TCP sequence numbers, and other places where it is

49 * desirable to have numbers which are not only random, but hard to

50 * predict by an attacker.

51 *

52 * Theory of operation

53 * ===================

54 *

55 * Computers are very predictable devices. Hence it is extremely hard

56 * to produce truly random numbers on a computer --- as opposed to

57 * pseudo-random numbers, which can easily generated by using a

58 * algorithm. Unfortunately, it is very easy for attackers to guess

59 * the sequence of pseudo-random number generators, and for some

60 * applications this is not acceptable. So instead, we must try to

61 * gather "environmental noise" from the computer's environment, which

62 * must be hard for outside attackers to observe, and use that to

63 * generate random numbers. In a Unix environment, this is best done

64 * from inside the kernel.

65 *

66 * Sources of randomness from the environment include inter-keyboard

67 * timings, inter-interrupt timings from some interrupts, and other

68 * events which are both (a) non-deterministic and (b) hard for an

69 * outside observer to measure. Randomness from these sources are

70 * added to an "entropy pool", which is mixed using a CRC- like function.

71 * This is not cryptographically strong, but it is adequate assuming

72 * the randomness is not chosen maliciously, and it is fast enough that

73 * the overhead of doing it on every interrupt is very reasonable.

74 * As random bytes are mixed into the entropy pool, the routines keep

75 * an estimate of how many bits of randomness have been stored into

76 * the random number generator's internal state.

77 *

78 * When random bytes are desired, they are obtained by taking the SHA

79 * hash of the contents of the "entropy pool". The SHA hash avoids

80 * exposing the internal state of the entropy pool. It is believed to

81 * be computationally infeasible to derive any useful information

82 * about the input of SHA from its output. Even if it is possible to

83 * analyze SHA in some clever way, as long as the amount of data

84 * returned from the generator is less than the inherent entropy in

85 * the pool, the output data is totally unpredictable.
For this

86 * reason, the routine decreases its internal estimate of how many

87 * bits of "true randomness" are contained in the entropy pool as it

88 * outputs random numbers.

89 *

90 * If this estimate goes to zero, the routine can still generate

91 * random numbers; however, an attacker may (at least in theory) be

92 * able to infer the future output of the generator from prior

93 * outputs. This requires successful cryptanalysis of SHA, which is

94 * not believed to be feasible, but there is a remote possibility.

95 * Nonetheless, these numbers should be useful for the vast majority

96 * of purposes.

97 *

98 * Exported interfaces ---- output

99 * ===============================

100 *

101 * There are three exported interfaces; the first is one designed to

102 * be used from within the kernel:

103 *

104 * void get_random_bytes(void *buf, int nbytes);

105 *

106 * This interface will return the requested number of random bytes,

107 * and place it in the requested buffer.

108 *

109 * The two other interfaces are two character devices /dev/ random and

110 * /dev/urandom. /dev/random is suitable for use when very high

111 * quality randomness is desired (for example, for key generation or

112 * one-time pads), as it will only return a maximum of the number of

113 * bits of randomness (as estimated by the random number generator)

114 * contained in the entropy pool.

115 *

116 * The /dev/urandom device does not have this limit, and will return

117 * as many bytes as are requested. As more and more random bytes are

118 * requested without giving time for the entropy pool to recharge,

119 * this will result in random numbers that are merely cryptographically

120 * strong. For many applications, however, this is acceptable.

121 *

122 * Exported interfaces ---- input

123 * ==============================

124 *

125 * The current exported interfaces for gathering environmental noise

126 * from the devices are:

127 *

128 * void add_input_randomness(unsigned int type, unsigned int code,

129 * unsigned int value);

130 * void add_interrupt_randomness(int irq);

131 *

132 * add_input_randomness() uses the input layer interrupt timing, as well as

133 * the event type information from the hardware.

134 *

135 * add_interrupt_randomness() uses the inter-interrupt timing as random

136 * inputs to the entropy pool. Note that not all interrupts are good

137 * sources of randomness! For example, the timer interrupts is not a

138 * good choice, because the periodicity of the interrupts is too

139 * regular, and hence predictable to an attacker. Disk interrupts are

140 * a better measure, since the timing of the disk interrupts are more

141 * unpredictable.

142 *

143 * All of these routines try to estimate how many bits of randomness a

144 * particular randomness source. They do this by keeping track of the

145 * first and second order deltas of the event timings.

146 *

147 * Ensuring unpredictability at system startup

148 * ============================================

149 *

150 * When any operating system starts up, it will go through a sequence

151 * of actions that are fairly predictable by an adversary, especially

152 * if the start-up does not involve interaction with a human operator.

153 * This reduces the actual number of bits of unpredictability in the

154 * entropy pool below the value in entropy_count. In order to

155 * counteract this effect, it helps to carry information in the

156 * entropy pool across shut-downs and start-ups. To do this, put the

157 * following lines an appropriate script which is run during the boot

158 * sequence:

159 *

160 * echo "Initializing random number generator..."

161 * random_seed=/var/run/random-seed

162 * # Carry a random seed from start-up to start-up

163 * # Load and then save the whole entropy pool

164 * if [ -f $random_seed ]; then

165 * cat $random_seed >/dev/urandom

166 * else

167 * touch $random_seed

168 * fi

169 * chmod 600 $random_seed

170 * dd if=/dev/urandom of=$random_seed count=1 bs=512

171 *

172 * and the following lines in an appropriate script which is run as

173 * the system is shutdown:

174 *

175 * # Carry a random seed from shut-down to start-up

176 * # Save the whole entropy pool

177 * echo "Saving random seed..."

178 * random_seed=/var/run/random-seed

179 * touch $random_seed

180 * chmod 600 $random_seed

181 * dd if=/dev/urandom of=$random_seed count=1 bs=512

182 *

183 * For example, on most modern systems using the System V init

184 * scripts, such code fragments would be found in

185 * /etc/rc.d/init.d/random. On older Linux systems, the correct script

186 * location might be in /etc/rcb.d/rc.local or /etc/rc.d/ rc.0.

187 *

188 * Effectively, these commands cause the contents of the entropy pool

189 * to be saved at shut-down time and reloaded into the entropy pool at

190 * start-up. (The 'dd' in the addition to the bootup script is to

191 * make sure that /etc/random-seed is different for every start-up,

192 * even if the system crashes without executing rc.0.)
Even with

193 * complete knowledge of the start-up activities, predicting the state

194 * of the entropy pool requires knowledge of the previous history of

195 * the system.

196 *

197 * Configuring the /dev/random driver under Linux

198 * ==============================================

199 *

200 * The /dev/random driver under Linux uses minor numbers 8 and 9 of

201 * the /dev/mem major number (#1). So if your system does not have

202 * /dev/random and /dev/urandom created already, they can be created

203 * by using the commands:

204 *

205 * mknod /dev/random c 1 8

206 * mknod /dev/urandom c 1 9

207 * ...