views:

1242

answers:

30

I'm hoping that we can all educate each other from our experiences of being misled by comments, or just emotionally scarred by them :)

By the way, I know someone already asked what is the best comment you've ever written, but I think we're likely to get more helpful (or at least, different) content here.


this wasn't mentioned as already asked when I entered my question.

+2  A: 

Ignoring comments of no worth, such as jokes and art, I think the top of this list should be...

Every comment that is factually incorrect. Documentation for a function or code block that is provably, or even obviously, wrong.

Sparr
... and I guess what should have been written is one that is factually correct :) True, though a pretty broad answer don't you think :) I was kinda looking for examples, things that do happen, or are quite subtle and easy mistakes to make.
Jesse Pepper
+28  A: 
// Return FALSE
return true;

...because of its superfluousness, verbosity (in relation to the code it documents), and the fact that it still got it wrong.

MandyK
How do you know there is not a "#define true FALSE", or the reverse, somewhere up there?
Sparr
Because that wouldn't have been meaningful to the Java compiler. ;)
MandyK
Ha ha, got you a good one, Sparr.
paxdiablo
Sparr has been dealing with a lot of females, it appears ;-D
icelava
I once wrote exactly this comment myself, and since I trust my comments it took me hours to find the bug...
martinus
+12  A: 
// increment the counter
count++;

What should have been written? Nothing.

Bill the Lizard
Some people do not know what ++ means. I kid you not.
icelava
You shouldn't write code for those people to understand
1800 INFORMATION
They should be fired.
Ed Swangren
@icelava: I had not considered that. :)
Bill the Lizard
It's wrong!~ It needs to be ++count; Damn.. doesnt' anyone grok efficiency anymore?
Adam Hawes
+4  A: 

I've seen this too often ...

/*
* function name: foo
* out arguments: None
* in arguments: None
*/

int foo( bar arg1, bar arg2, bar arg3);
hhafez
totally agree! it makes you wonder if those comments like that are just a maintenance overhead, and you should put a comment about the arguments when you think the caller will need it.
Jesse Pepper
Comments only seem to be written and never maintained. (In practice.)
peSHIr
@peSHir That's exactly right, comments are rarely maintained
hhafez
A: 
// return the result
return result;

because: it's superfluous

should have been:

return result;
Jesse Pepper
+4  A: 

In production VB6 code as supplied from the vendor. Halogen was a comm library supplied from the same vendor

'Wrap Around to stop Halogen Shitting itself

benPearce
+1 for making me laugh
Jesse Pepper
But they almost got it right. They just needed to put a "HACK: " in front of that.
lc
laughed...had to give it a +1
bcasp
+2  A: 
////////////////////////////////////////////////////////////////////////////////
// D**** P********'s silent soapbox:
//     I found the following in the header file, which is stuff you should not 
//     find in header files (variable definitions and non-inline function 
//     bodies.)  The only reason the program compiles this way is that it is 
//     written in just one source file, when it really, really, REALLY should be 
//     broken up.  Into, say, oh, 15 different modules.  This source file is 
//     so large, the most bloated MFC module is less than half the size.
////////////////////////////////////////////////////////////////////////////////

I thought it was very passive aggressive, especially for a co-op student. One shouldn't go adding comments like this to other peoples code.

FigBug
why not, it sounds like a fair comment doesn't it?
Jesse Pepper
That comment block goes a long way to help the file-is-too-long problem, doesn't it?
lc
Agree with Jesse, why not add such a comment?
0xA3
Why not? When you work in large team, brought in from the outside and you find something that you know shouldn't really be done and you cannot/will not change it there and then for whatever reason, I often add comments like this. Okay, not worded like this, but... ;-)
peSHIr
Maybe it was FigBug's code...
Ed Swangren
If it's possible for someone to add a comment like this without anyone noticing, then why wouldn't it have been possible to actually break up the code into multiple modules? There might have been good reasons, but if not, it's more productive to fix issues instead of just complaining about them.
Reuben
It's never more productive to "fix" issues rather than complaining about them. Fixing issues introduces bugs. I would have added a comment to that effect too.
Adam Hawes
+10  A: 

i can asure you i am not lying these were comments a friend find while giving support to a system.

1.-
    //This function gathers all the data it needs to set in one loop, then sets it in a second. //Why?
         //This is so that the actual data change is all done as close to atomically as possible. 
        //Implementing locking on this data would be difficult and complicated, so instead of "fixing"  
        //the problem, we "minimize" it.

2.-
    // a hack to keep validator happy. it never validates but has sonmething to assign otherwise would get nasty error:ControlIdToEvaluate not assign



3.-     
        //The following code was cobbled together very quickly and is now held together by the
     //equivalent of peanut butter and prayer. Some of what it does seems stupid -- some of 
    //those things actually are stupid, but some are necessary.

the code is not available due to confidentiality agreements but they are true

Oscar Cabrero
+8  A: 

This comment preceded a particularly hairy piece of code that the author obviously thought was too hard to understand by mere mortals.

/* Here be dragons */

Personally I would have preferred an ever-so-brief explanation of what the code was meant to do, rather than a warning.

paxdiablo
Well, are you a dragon? Probabl not. Then you couldn't understand the comment anyway. So tired of these mortals... sigh.. oh shit, burned my hand again.
mannicken
Actually, I would have to be a dragon-slayer, since the comment is warning about dragons.
paxdiablo
Gamecat
Kevin
I've always associated this phrase with early seafaring maps.
Don Music
Matthew Brubaker
Bah a warning is all that is needed. If it's so dangerous that the author felt the need for that comment, stay the hell away from it and let it keep working whatever obfuscated magic it does :)
Adam Hawes
A: 

I once saw

// ???

at a certain place and that truly made me wondered for a while.

PolyThinker
I think of shorthand for// TODO: work out what this code does and comment itSo i wouldn't say it's _that_ bad
Jesse Pepper
I think I've used it in place of "// WTF!?!" before.
Andrew Kennan
@Andrew: Exactly. Not quite the thing you want to see in someone *else's* code...
lc
+1  A: 

Well, let me put it this way: I once worked on a legacy application which was intentionally written in an obfuscated fashion so the original author could continue to milk consulting fees when the software needed to be maintained. One time, I was curious so I grepped the code comments for the word:

nightmare

There were 22 matches.

Of course some of the class names were Banshee and Medusa. Did I mention it was a business application?

jonathan.cone
And did you turn to stone?
Gamecat
+7  A: 

Leaving aside all the crappy comments one finds in code written by beginners, I think the worst comment of all time has to be the famous one in the Unix kernel:

You are not expected to understand this.

A close second is one of Lennart Augustsson's; unfortunately I can't find the original code, but it was something like

apply f = apply f    -- the ice is getting thin here

It looks like apply is just an infinite recursion, but the apply on the right is actually a compiler intrinsic, so it's OK. But as Lennart said, the ice is getting thin...

Norman Ramsey
+2  A: 

Comments that is written in foreign languages where most people in the project use and speaks English!

Lester Cheung
+4  A: 

// THIS SHOULD NEVER HAPPEN

Seems popular on Google Code

Or

// not sure why this works!!
CMS
What's so wrong with "THIS SHOULD NEVER HAPPEN"? Unless I'm misunderstanding, I'm expecting something like if(true) DoSomething(); else /*THIS SHOULD NEVER HAPPEN*/ throw new TheSkyIsFallingException();
lc
Well if there is a "this should never happen" situation, you use an assert else you will never know if it is going to happen.
Gamecat
I use this sometimes. If I call a method that can throw a "FileNotFoundException", and I know the file was there 2 lines above, and good errorhandling will take too much time to make, I just log the error at let it crash. Then this comment is needed.
myplacedk
+1  A: 
// To be fixed later

Why not just build more crappy code over the old ones...

Should be:

Fix it now and build the rest of the code over working ones.

Peter
A: 

I'm guilty of adding a header with a "last modified" date in it that I perpetually forget to update as I make changes to my code. I should probably just start naming it "date created".

Soviut
Isn't that what the last modified date is for in the file properties?
lc
That file system property might not survive source code control and/or backup procedures...
peSHIr
(Then again, last modified date is often something your source code control can update in a file header for you!)
peSHIr
Your source control should also be able to to tell you when a given file was modified
JoshJordan
Exactly. I rely on source control now to tell me the date these days.
Soviut
+2  A: 

I don't remember the exact wording but back in the times when I did some MFC stuff I once came over the following comment in one of the header files:

/* No longer supported. Never worked anyway. */
0xA3
+1  A: 
//TODO HÄ? WHAT YOU'RE DOING HERE?
furtelwart
A: 
// Fix it

Because you never know exactly what portion of the code is related to the comment, what's the history of this code and what the author had in mind when he wrote it.

gizmo
+1  A: 
 //The last minute express rolls again...

I find this from time to time in our legacy code. I guess that happens when you get set unrealistic deadlines.

Hmm, I have a compound fracture, where did I put that sticking plaster???

Matt Johnson
A: 

// Do Stuff

or

// You can't get here from there!

Ryan ONeill
A: 

French comments to french code. No I don't speak french :)

hhafez
+1  A: 
bool some_fun( something )
{
    if( something )
    {
        return true;
    }
    else
    {
        //return false;
        return true;
    }
}

Not just a comment, but it's not funny if you don't see it in context.

Noaki
A: 

We had a consultant working on some code that wrote

// Little bunny wants his carotts back.

He even spelt Carrots wrongly. The context did not involve bunnies or vegetables: it was some GUI code for a corporate application.

Fortyrunner
+1  A: 

// Not sure why this works, wo I'm leaving it alone

or

// I don't know how this works, but it returns the right answer so who cares

A: 

There is a legend of a program, written in assembler, with the single comment

; happy birthday, Wolfgang

-because the instructions it was attached to, when converted down to the object binary code read 17560127, or some variation thereof. I never saw it, but the legend persists....

OTOH, I really did see the source code - again, written entirely in 8086 assembler for a BIOS (this was circa 1987), that had very few comments in there at all. I never thought that the listed owners actually wrote that though.

Alister Bulman
A: 

In an exception handler:

-- what should we do? log the error ^^? --

That is really bad... There has to be an exception handler with log functionality or a new exception.

furtelwart
A: 

Har! I found the following in code:

//fprintf(stderr, "Cannot open [%s] for reading\n", filename);
fprintf(stderr, "Cannot open [%s] for reading\n", filename);

I see a lot of these in the codebase I inherited last year:

//TODO: Don't crash here so often
//TODO: Needs critical section
//TODO: Implement this function

And all in real-live called code. Conceded I think I added the second one when I realised that it was needed, but there's a lot of todos in live code for new features that we obviously ran out of time to build.

Adam Hawes
+2  A: 
# FIXME -- Use proper argument name
def get_flatten_list(foo):
    ...
aatifh
A: 

In a Cocoa Touch app:

[sweet release]; // Ahh...
rpetrich