- 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
Comment On Comment On Comments
Admin
Admin
Comments certainly don't tell what the code does. The code is there for this. Comments can tell why the code does something.
At least, that's how I see comments ...
Admin
I can well believe Dante's comment as being part of some crufty old template handling system, probably lovingly thrown at the wall in Perl.
Admin
Last one probably isn't a WTF.
Likely their server-side process replaces the text "<!-- INFERNO -->" with some real HTML before sending it client side. Crude, but it works. Some idiot probably thought it was just a useless comment and deleted it without asking anyone, hence the comment before it.
Admin
except that is doesn't say why INFERNO is needed... and when it would no longer be untouchable.
Admin
Comment On Comment On Comments.
Admin
Please be careful when spelling carefull.
Admin
Comments show where the bugs in the code are: The developer thought that it was difficult enough to require an explanation and therefore this is where they most likely made a mistake!
Admin
I couldn't agree more.
Except there are some 'Agile' people who out there who 'don't gold plate' and will tell you documentation is just another thing to maintain. Saying 'why' usually changes less often than 'how' but apparently we are all to stupid to understand their genius (or their Worse Than Failure code).
Admin
WRONG. Comments should show WHY code is needed - its context in the real world, not IT speak. It should be written in a way that the business would understand. They should be language and implementation neutral, and concise enough to be written carefully. If your code has comments saying 'add one because we've got an offset I can't figure out' then you've got a crap team. If all your team don't comment then please let us know your company so I never apply for a job there.
Admin
Probability that another developer reads (and tries to understand) the code: 1
Admin
From an actual project I did at University:
[code]class Flash /* AaaAAAAAAAHHHH */ : public PhysicsBehaviour // Saviour - of the UniVERSE! { ... }
Admin
The thing that really annoys me is comments that indicate the person writing the comment either had no idea what the code was doing, or worse was too lazy to refactor it to make sense.
My old job was littered with comments like:
// not sure where this is used
// why is this here?
// not sure what this code does
// there is probably a better way to do this
and it annoyed me because it was always the same guy, and this guy would never take 5 minutes to address it; he would copy/paste code 3+ places rather than spend the time to refactor it to a method, or just comment out a large block of code and never remove it (despite the fact we used version control) because he was worried that COMMENTED OUT CODE might break the system (no joke he said as much once).
Bad comments are worse than no comments at all, and best of all is code that is actually readable without needing a comment to explain it. Sure, maybe have a comment if the code is for a particular workflow process, but in most cases I firmly believe code should document itself by being clear and concise.
Admin
Beginners comment nothing. Apprentices comment the obvious. Journeymen comment the reason for doing it. Masters comment the reason for not doing it another way. -- Richard C. Haven
Admin
// begin comment activity 399412
Don't you just hate it when you see this retarded shit everywhere? This is the wrong tool for the job. This is what source control history is for.
// end comment activity 399412
I've actually seen this, except "Bob" left the company years ago, so I had no one to yell at/ask about it:
// Bob added this for paging new AbstractFactory().getManagerObject().doPaging();
Admin
Sometimes I'll see, and add myself, comments like:
// Added by W.Jack, 11/11/11, Problem Report 12345 // If the mode is X, then ensure Y is set
It's also described in the version control history, as well as the problem report description, and all that good stuff, but if you're in the middle of reading/examining/editing the code, a quick 2-line note like that to remind you of some special circumstance that was taken care of, is quicker than stopping to do a diff and then firing up the reporting tools to figure out why.
Obviously we don't go overboard, and we wouldn't bother to comment silly stuff like:
// Oops, forgot to check for null pointer here
// Fixed spelling mistake
// Removed this entire function as it is no longer needed
But the major logic bugs, "don't forget to do X before Y", etc. are helpful.
Admin
I'm an agile guy :) I don't write a lot of comments, but I make sure the one I write are useful and I make sure I write comments where it's needed.
And if I was in the situation where an important markup had not to be deleted, I'd certainly comment not to delete it. In agile, you are not afraid to change code that's working to make it better. And there's no code ownership.
Admin
Admin
Admin
WTF? I looked at the identified problem, and traced through the code, withoutrunningit. I spent ten minutes correctly identifying why it didn't work, and about an hour unsuccessfully removing all traces of withering contempt from my emailed discussion of the problem.
Admin
Admin
I think you are waay to subtle for anyone to bite on this troll attempt.
Admin
I do kind of hate those kind of
kind of comments since that's what version control is for, but I do kind of see where it might be useful if you crack open a code file to see where a fix was done.I hate hate hate HATE having huge "change log" blocks at the top of a code file though.
Admin
... I stand corrected.
Admin
If the comment already says what is happening, probability you can paste this into an email: 0.8
Admin
Admin
Comments: Why Tests: What Code: How
Admin
Really, Remy? That's the only comment you put in this one?
I can't tell if you're taking a minimalist tack with your humor, or if you're just losing your touch... ;-)
Admin
I disagree.
The language for why should be the language that the next programmer can understand.
Product documentation is where you write the whys that the business guys can understand. Business guys have no "business" reading your source code, unless they are fully apt developers themselves. Even then, if the VP is reading code, he doesn't trust his teams' leaders and there's a management issue.
Not only that, but comments CAN describe what a section of code is designed to do, if the code is complex and requires that information to maintain it. Example, code that performs a complex algorithm, I usually comment what the algorithm is supposed to do and how it should accomplish that. In these cases, any sufficient self-documenting function names or class names would end up a WTF article for their names.
In short, use common sense when writing comments, and target your audience. That's what you're taught when writing product documentation, so the same rules apply for comments, for the same reasons.
Admin
And that my friends is why software is often so poorly designed, badly written, buggy and late - because IT people think domain knowledge is 'management speak' and refuse to use it.
Admin
Admin
Well, the time when the INFERNO thing is no longer untouchable is the time when they rewrite the code, which while that is not going to happen any time soon still has a much greater chance than that anyone is going to update the comment with a better explanation.
Admin
I give you a 50% - The note about the reason for the fix is good. The note about who added it, when, and for which problem report is irrelevant to the code itself.
Instead just put the reason for the fix and leave the rest of the information in the commit message. If you come to such a line and want to know who added it when for what bug ticket (or other circumstantial information about the change itself) the source history (svn and I'm sure other more sophistocated version control tools have a nice feature called Blame or Annotate which will show you who last changed each line when and what the commit message was) is not so hard to access, especially when using a modern IDE with proper VCS integration.
Admin
Far further from the truth than you can possibly imagine.
Admin
For all that comments should document "why it does" and not "what it does", there are enough business processes that are non-obvious and poorly understood that it's often easier to explain what the code is doing, too.
For a recent project, I had to write a bunch of math. I understood the math when I wrote the code, but I do not understand it any longer. I do not know what the code does, other than "this derives this set of calculations from the input waveform". Without comments to walk me through the math, I wouldn't be able to maintain the code.
Admin
I see absolutely nothing wrong with the existence of comments like "this is a hack", "I don't like the way this is done, but I couldn't think of a better one", or even "this isn't working right now, beware!" Yes, in a perfect world, everything would always be perfect, but that isn't the world we live in. Sometimes we need to commit things that only mostly work, or that totally work but aren't pretty, and immediately above such a code section is the perfect place to document that fact (at least assuming you aren't working with a noncompiled language where the source will be pushed directly to curious consumers :p).
What I really love are people who feel the compulsion to comment every public method... but don't feel the same need to have those comments actually be useful, or even mean anything. I worked with one guy like that, who thought it would be a good idea to run a comment auto-generator. I guess he thought it would encourage us to replace the autogenerated comments with real ones when we saw them? Actually it just encouraged us to be amused, and then ignore them. Properties with names like FirstName, for instance, don't really need comments. And what they definitely don't need is comments like:
But at least that's still readable. What they really don't need are comments like (real examples!):
Or:
Or:
Or:
Or even:
Admin
Makes sense.
All one must do is stand back and realise that no guideline on commenting is gospel just like no development methodology is perfect.
Every approach has its place in any reasonably interesting project, and as long as the people writing the code continually strive to improve their craftsmanship then the chances of a successful outcome and straightforward legacy maintenance are good.
Admin
If you are writing a "what it does" comment, you will usually find it more useful to use problem-domain language rather than solution-domain language. This isn't so that the business-side people can understand the code - that theory of code creation was thoroughly, if unintentionally, debunked by the inventors of COBOL back in the Fifties.
No, it is because that way the comment can add something above and beyond the content of the code. "Add fleen to ogglefloggle and store the result in argleflargle" doesn't add anything to this line of code:
In fact, well-chosen variable names, which 'fleen', 'ogglefloggle', and 'argleflargle' are unlikely to be, will most often remove any need for a comment here. A more complex series of operations would probably benefit from a description of what, but equally you could just write a reference to a book or other piece of descriptive reference material. "Perform the routing summary calculations as described in [Miffle and Swub 1998]" might be a suitable example.
Admin
What are the chances that a developer, that can understand the IT-speak that is the code, was given tasking in business terms? Just because I can figure out what a block of code does doesn't mean I don't need to understand the business logic that makes that code necessary. This is the same reason why you use variable names that are descriptive of the business logic: a=bc has no inherent meaning, but amountBilled=multiplierDiscountamountTaxed does. Which code would you rather see when tasked to ensure the discount does not exceed 15%?
Admin
I inherited a web app with a ton of these comments:
I didn't replace the comment, but when I added exception reporting after it, let's just say that we were able to solve most of the bugs in the app.
Admin
Am I the only one disappointed that clicking "INFERNO" in a Remy article does not generate disco inferno popups?
Admin
Long, long ago I had to add a comment like that (but the opposite sense). I forget the exact details, but I seem to recall it was a TurboPascal graphics library. For some reason calling a library function had no effect, unless you called it twice (same function, same parameters). So I ended up with something like:
It was a mark of how desperate I was that I even tried such stupid code, but it worked; so I commented it and moved on.
Admin
Which shortly thereafter DID happen and the resulting notification window was submitted to the Friday Photo collection on TDWTF.
Admin
I think the "don't know why this doesn't work" comments are pretty bad on their own, but definitely a WTF when compounded with the fact that they were bugs, and ones that were easily remedied.
As for a weird issue like calling something twice to get it to work, if you can't modify the referenced method, and the double references work, then it's not a WTF.
Admin
FTFY
Admin
It was mostly stupid stuff like this:
It gets even better. The guy responsible for the code came back to the company, and I left shortly after that. I can only imagine how bad things are there now.
Admin
But it's not a good comment: It tells us us just that he wouldn't put those things in an article directly, not but why (which is something I've really never understood).
Admin
Especially for "special" behaviour that I expect will be revisited soon. So when some other (or probably the same) guy from SomeCustomer demands contradictory behaviour a few weeks later, we can ask them to sort it out internally first. And if a coworker gets assigned to it, they can contact me easily when necessary, without digging through revisions.
Admin
I know it is a tradition on this site that nobody has read the spec, but in the real world a developer not knowing the spec or describing the business logic in code comments instead of the spec (so that you can easily copy'n'paste it into a mail when anon's boss asks for the spec) is TRWTF.
Of course it is fine to add a reference to the spec in the code comments.