- 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
} // Close code block
Admin
I got 3 and I have no idea why... ;)
Admin
Paid by the line... (code or otherwise)
Admin
I think comments are unnecessary for most of the code. I demand everybody code for my desires. I think that anyone who needs comments is too stupid to write code. Finally my inability to use grep to remove comments from my own view has nothing to do with my own stupidity at all.
Admin
Admin
I'm not sure how your example demonstrates anything. First off, your function f doesn't achieve the same results as the original code, since it doesn't modify the value of x. Secondly, the original code could be easily written in one line:
y = ++x * 10;
No need for refactoring. I think you misunderstood the argument. When you have complex pieces of code that include lots of loops and conditions, it might be a good idea to move some of that functionality to a subroutine to improve readability. Nobody thinks refactoring simple code is a good idea.
Admin
I love it!
Admin
One of the (IMHO, few) places where comments are truly necessary is where the correct code "looks wrong." This may be because you're accounting for a fault in different system (if it's yours, you should have a comment in that system, but then you would have fixed it, right?) or something similar. The idea being to let future programmers (including yourself) know that it's right, and not just a mistake. It also helps if you make that comment clear enough that maintainers can tell when that condition no longer holds and can "fix" it properly.
Most* other comments can be covered by good variable / module / function names and clear code. Any other code comments should describe why you're doing something. I can see what you're doing.
*With the exception of brief module, function and variable descriptions as required by your coding standards and good sense.
Admin
Evil! Love it!
Admin
Yuck. Side effects. YUCK. Just go with:
x += 1; y = x * 10;
Admin
are you sure there was no coment for the method?
Admin
I took a data structures class in college, and I swear that fully half (if not more) of the class was learning how to comment code rigorously, where by "rigorously" I really mean "like an obsessive jerk." Our "correct" comments looked pretty much like this in terms of verbosity.
Admin
Admin
Is this some sort of attempt to implement Literate Programming [url]http://en.wikipedia.org/wiki/Literate_programming[\url] in Visual Basic? If so, the person who wrote this is going to need a programming environment a lot more sophisticated than Visual Studio.
Admin
And I'm going to need an environment a lot more sophisticated than this BBCode editor. Like one with a preview function...
Admin
Admin
Admin
} // end case
Mostly introduced by people, telling you, a 4 space indentation is enough (3, 2).
Morons, everywhere.
Admin
A rather big method with lots of conditions and loops that might be hard to follow... Spaghetti!
Admin
Amen to that! Nothing like getting the code all pecker-tracked up with messy comments. Like throwing dirt in an engine.
Fix it and test it. Use version control software for diffs.
Admin
Amen to that! Nothing like getting the code all pecker-tracked up with messy comments. Like throwing dirt in an engine.
Fix it and test it. Use version control software for diffs.
Admin
And comments get stale as the code slowly drifts. So you have to figure out what the comment means, and what the code is trying to do.
Admin
And comments get stale as the code slowly drifts. So you have to figure out what the comment means, and what the code is trying to do.
Admin
Clear code tells you what a block of code does. Clear comments tell you what a block of code is intended to do.
One of these two informational needs is more important than the other to a maintenance coder. In my experience, it's been the latter that I've always wished for.
Admin
Unlike those unsilly languages that use descriptive techniques like putting "void" in front of the method name, right? If you use a language that reads more like English, perhaps you'd need less comments.
Admin
If you find yourself needing to comment most of your code so that someone else can understand the intent behind it then you're writing shit code.
Admin
Ah yes, the classic call of the person who never has to do maintenance on someone else's code, nor ever write code that others will have to maintain. (The last possible category being assholes who don't think about how their work affects others, but I'm sure you don't fall into that category.)
I'll be sure to think of you and your extremely helpful advice the next time I encounter a function named "Q_rsqrt" in the "util" class, and wonder what the hell "i = 0x5f3758df - ( i >> 1 );" is doing in the code, why it's there, and what it was supposed to do.
Strangely, a comment explaining the intent of the function, and a second comment explaining the intent of the magic number would save literally days in attempting to diagnose and correct the problem in a way that better naming of the function and variables won't.
Amazingly, some of us have to fix the bugs of so-called "non-shit" programmers after they've already made the mess and left, so given the choice of having clear comments and no comments, I'll always take the former.
(PS: Yes, this is a particularly famous example, tweaked to intentionally insert an easily-made bug, but it illustrates my point well.)
Admin
In one module at work I have to write comments sufficiently verbose that someone can read them (and not the code) and still understand, at a high level, what the code does and how it works. This is because export requirements prevent us from giving this one particular customer the source code (usually we do give out our sources), so instead we deliver documentation from Doxygen, which we configure to emit all the comments. The result is basically literate programming. It looks really nice, actually, so long as the programmer is responsible enough to keep the code and the comments in sync. But it all goes to hell in a moment if the comments are unmaintained.
This module contains several places where there's just a single line of code that does something very profound and difficult to grasp. These individual lines are preceded by paragraphs of comments which explain the ramifications and design considerations.
For interesting and informative comments, have a look at the SQLite source code some time.
Admin
My goal when documenting my code is to get the next programmer up to speed as quickly as possible. I imagine all the easy mistakes that can be made from ignorance, and the comments I write are specifically designed to prevent those mistakes. I think of all the things that weren't instantly clear to me, or that I suspect less experienced programmers can outright misunderstand, and I give them special attention. Basically I write the documentation I wish I had before I started working on the module.
This also translates to the way I write my code. Whenever possible, I write it to maximize maintainability. And when forced to write tricky code, I do my best to make up for it in comments and external documentation.
Admin
mmmm... aaaaah... duhhhh... The one next to the Submit button ??
Admin
the biggest wtf i see here is...
"Output system error message to user on form under form title and send details to database"
this means, every time a user enters an invalid SSN (assuming there is some sort of business logic in the set property) into the text box, an error will be logged to the database. How could an error log like that possibly be useful?
Admin
Did you notice the structured exception handling? This is VB.NET, not VB. There is no On Error Resume... in VB.NET.
Admin
Admin
Admin
Besides, the kind of comment you get out of compulsive commenters would be
unless it's
In my experience, quality of comments is inversely related to their amount.
Admin
Admin
A well-named function if ever I saw one. Not!
Fabian
Admin
Why??? What's so WTFy to write On Error Goto instead of try..catch? Is the meaning of the words better chosen or is it because you need to write more letters in VB?
Admin
C++ and Java are some of these silly languages that need a key word to describe the one and only possible start of a function/procedure.
Admin
For me the bigger crime is to give written evidence of stupid one is...
Admin
For me the bigger crime is to give written evidence of stupid one is...
Admin
"// output: The exact value of pi." A good example of mis-leading comments
Admin
What's wrong with 4 spaces? I use 4 instead of 2 as many C-guys do. But the code is more difficult to read for me with only 2 spaces.
Admin
Ununstrangely, there is no name for that particular magic number. The function is the not-as-well-known-as-it-should-be technique for computing fast reciprocal square roots, and it basically depends entirely on using IEEE floats. The best way to explain exactly what it's doing to a maintainer is to tell them. In a comment.
What language do you use where you can have more than one entry point to a function/procedure? ;-oAdmin
public/private function XXX public/private procedure XXX
QED
Admin
Neither "function" nor "procedure" is a keyword in either C++ or Java.
Admin
Admin
Absolutely! That way when a change elsewhere causes a break, you have no comments to understand the nuances of the original code and why it expected any particular set of conditions. Way to plan ahead and consider others at the same time!
Admin
I hold pretty firmly to the belief that comments in modern programming languages should only be used to explain the "why" and not the "what" or the "how."
Addendum (2007-10-02 11:20): I see comments like this in the system I've inherited:
'Set file lock SetFileLock()
Admin
Comments are only useful or helpful to explain the obscure quirks. Otherwise they are misleading junk that will never get updated.
Why would you need a comment to explain the intent of a method named "calculateMonthlyInterest()" or "suspend()"?
Some of the code I maintain (written by a team of fresh out of college grads in Bangalore 5 years ago) is WTF heaven. 7,000 line methods, copy/paste errors the lot. The comments don't help and are often wrong.
"i = 0x5f3758df - ( i >> 1 );" is an obscure quirk that deserves a comment. I posted earlier in the thread, that's the only case in which you should need them - to explain stuff that isn't easily made self documenting in the code.The method name is shit. Instead of a comment saying what the method does, it would be better for the name to actually mean something.
You don't get a choice of clear comments or no comments. You get a choice of randomly scattered inconsistent and out of date down right misleading comments or hardly any comments except where they're absolutely needed to explain *magic*. The latter is the only useful option.