- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So, what's so bad about the grammatical error?
Admin
I once dealt with a piece of code that implemented a persistent internal database in C++, with pointers and all. It had the following comment:
I didn't even need to touch it to break it -- just changing from a 32-bit architecture to a 64-bit architecture did that all on its own.
Needless to say, when I fixed the code, I removed the comment.
Admin
This made me think of a comment I once saw in production code, saying that the code immediately below didn't work and nobody knew why.
I stared at the body of code for about ten minutes, following the chain of events, and found out why. This revelation was not well received by the people who had produced the code in question.
Admin
mandatory reference:
https://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered
Admin
This comment has leaked into production.
Admin
I miss when Remy used to hide interesting comments in the article source. At least my Cornify bookmarklet still works.
Admin
Just the good old:
and
which, inevitably, get committed and pushed.
Admin
Comments can sometimes lie. Code never does.
Admin
| Comments can sometimes lie. Code never does.
int one=5; int ten=6; int eleven = one + ten; // true
Admin
Shallow copy of object created by a pass-by-value function argument.
Admin
There's your WTF ^^^
Admin
I bet they are ..... Mostly Harmless
Admin
Sounds like someone already took out the dangerous code and left the comment. Or, to quote the Rocky Horror Picture Show, they removed the cause...but NOT the symptom.
Admin
Yeah, people tend to hate it when you fix their mistakes. Corporatism 101.
Admin
Those were probably not the lines that originally followed. As usual, the code was changed but the comments were untouched.
Admin
my favorite comment ever is "this doesn't really do anything anymore". So you took the effort to write the comment, but not to remove the unnecessary code? Great work!
Admin
Those comments exist where the process to make a small change is too unwieldy.
Admin
Or there's insufficient tests/testing to ensure that removal of the "useless code" in fact breaks nothing in that one business-critical component that nobody really understands anymore.
Admin
And then people ask me why I’m against the policy of always putting comments on a separate line.
Admin
I remember a few years ago seeing a comment that went something like: "This code is obsolete. If still here by March 1998, please remove it"
I'm pretty sure the code was commented-out, but it and the comment remained for almost 20 years before I found and removed it.
Admin
Q.E.D.!
Admin
Well, the comment only says to not let the code pass into production, it does not say anything about the comment ...
;)
Admin
Years ago, I ran into a function whose assumed inputs (top N elements of the stack) were documented solely as "you don't want to know", and had to wade through the code to reconstruct what they were (N turned out to be 8 in that instance).
Admin
Complete source code:
// WARNING!!! Special case for [external API] testing. // DO NOT LET THIS PIECE OF CODE FIND IT'S WAY TO PRODUCTION #if development DoSomethingNastyWithApi(); #end if
Admin
I feel like comments are an important tool to explain why you're doing something. Except for regular expression comments, they shouldn't also say what, because what should be pretty clearly conveyed by the code itself. Regular expressions can be pretty obuse, though, so if the regex is complicated, it's excusable to explain what and how the regex is doing this task.
Some of my coworkers tend to feel like comments are a good way to retain code that's stored in version control so that we can look back and see what had previously been done here. I mean, back when the code was being developed, because they stop making comments after they feel like they're ready for deployment. And, by 'here', I mean in the company they work for, because they have this distinct tendency to move comments, both theirs and mine, more or less whenever they copypasta.
It's probably also noteworthy that happens before they make any edits to the code, including deciding the whole copypasta was a bad idea, and delete all of the code they copied, but leave the comments behind.
At least it usually feels pretty safe to reject proposed changes that simply add a random selection of comments from wherever to code that needs correction, and then call it good.