- 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
I love VB. Who needs block comments anyway? (Frist?)
Admin
i mean, we programmers are a weird bunch, we rant when there are no comments, seems we don't like when they are ... whatever these are ... when is it "just right" ...
Admin
Nice WTF, VB... and those comments are pretty much their own WTF. :)
Admin
While method header comments or .NET documentation comments are a different animal, in-body comments are just right when they are sparse enough that you only notice them when you need them, but detailed enough that they make the surprises apparent. In other words, don't tell us about language features(unless they are VERY obscure), standard library functions(unless they are obscure or there is a workaround\known problem that affects the code), or standard idioms like iteration. We should be able to get that information from the code itself or the code is bad.
In my opinion, when commenting code directly, just tell us why you're formatting a zipcode as a float or dividing the social security number by 6, or that a bug was fixed here. There is no real need to duplicate the line of code in English, regardless of what college teaches you. Simple methods don't need block in-line comments.
Admin
I'm shocked, SHOCKED! that this otherwise careful and thorough programmer failed to comment the "End Try" line.
Admin
What does "End Sub" do?
CAPTCHA: Ha, ha! I'm a robot and I fooled this stupid test!
Admin
//above here is the subject, entered to detail reply
//Bellow is comment body, where witty retorts are entered. Haha this is a sweet WTF.
//bellow here is where you write you captcha if you didn't login
//bellow here is where submit is pressed to submit comment
Admin
Admin
benj
Admin
Admin
No comments is not good, now I provide comments it is not good either.. you just can't win can you!! ;)
Admin
That, IMHO, is the duty of a header comment, which I excluded in my first paragraph. Something like:
//FuncA //Description: Does X, Y, Z //Remarks: etc, etc void FuncA(X,Y,Z)
With something as simple as that and short, to the point methods, you shouldn't need a comment at every line for clarities sake. I'm not going to say you should never comment, just that a comment should be as well thought out and utilitarian as every other line of code, not throw in excuses not to make sense IN code.
Admin
Admin
Getting paid by lines of code is sooo 90's, now we are paying for lines of comments!
Admin
maybe not by lines of code, but hourly. and it takes a while to type that crap out
Admin
Admin
Admin
It won't remove the need for comments completely, to be sure, but it might reduce it.
Admin
VB is one of those silly languages that uses different terms for methods that return a value (Function) and methods that don't return anything (Sub(routine)).
Admin
My personal rules of commenting:
Admin
And by the way, what's with the subErrorReporting name? What's that sub prefix for?
Admin
Admin
You would hope that they would know what try, catch, and = are, but you would be surprised.
I used to write comments on this level of difficulty for my old boss, just in case he had to maintain the code someday. And as it turned out, he did!
Admin
If given a choice between superfluous over-commenting and no commenting (or not enough) I'll take the over-commenting any day of the week. You can always delete unnecessary comment blocks if they're that annoying.
Besides, isn't complaining about this like complaining about someone who compulsively uses their turn signals after checking their blind spots when changing lanes? I mean -- I agree that in this case the commenting was grossly unnecessary; but I can think of far worse crimes.... coding in VB for example!
Admin
On occasion, I'll comment iterators if they're nested or I just think it'll be easier to read.
Admin
Why comment when you can just put it all in the function name? If you don't have carpal tunnel then aren't doin' it right.
public function functPoindexterIsMyCaption as boolean.
Admin
I spotted this in some PHP code the other day:
// start the session session_start();
Now can anyone tell me how that comment added any value to the code?
Admin
subErrorReporting means that some company is insisting upon using Hungarian notation for function names. Talk about going way over-the-top.
I'm sorry, I don't care what any of you say, this is moronic. This is someone who is wasting their company's time. And, anyone who cannot read this code without the huge comment block is also a moron.
This code is trivial and should require zero explanation to understand. If you do require explanation for this code, you should be in school and not getting paid.
Admin
While the act of commenting the code is commendable.. what's the old rule? Useless comments are worse than no comments at all?
Admin
The rule with comments is always to use them to make the code easier to read. Whatever that means. It takes good taste and a proper sense of code-smell...
Admin
Bother: forgot to bbcode the italics... :-(
Admin
When I hear "CMMI", this post is more or less exactly what comes to mind.
Is that unfair?
Admin
Seriously though, this gal is probably the only one on her team who doesn't use On Error Goto... for her error handling. She's just trying to stop the other eager veabers from putting her code inside an On Error Resume Next in case there are any unhandled errors.
Error handling in VB - The real WTF!
Admin
You're new here, aren't you? :)
Admin
Yes.
Admin
This reminds me of college. I often helped other students with their programming, and I could always tell who had taken classes with which professor, since they invariably used the same idiotic block comments in front of every file, function, and other major structure. The block comments included worthless information such as the freakin' hostname of the computer used to write the code!
Understand that this would be years after the student had passed the course in which they were (ahem) programmed to use this comment format. When asked about it, they would tell me that they just got into the habit after being required to do it for so many assignments.
Imagine these poor souls when they get real jobs. Or, imagine the poor employers who hire them! How very sad.
Admin
Funny that this topic should come up now. Today I'm working on an update to existing code, and here's what I found when I opened the source. Looks like the previous coder had his output switch set to "verbose":
Admin
I couldn't agree more!!!!
Admin
If I'm writing something in a tinky tonky toy language like PHP, I often won't start by writing a detailed design. I'll think for about 5 minutes, and then write the entire file, using comments for any bits that are boring, and/or can't expand without looking away from the file.
eg:
//start session //connect to db //select list of all users //output start of table //for each user // output row //end //close table //close connections
The comments aren't designed to help you, the reader, but more me, the writer. They probably shouldn't be left around, think of it as mental scaffolding.
On the other hand, maybe whichever colleague wrote the code has evaluated his peers and found that those sorts of comments are required..
Admin
Admin
For me the worst part is the block style. It take an effort to even see the real code buried in the comment.
Something I like better than comments is whitespace. I like 120 character wide code plenty of blank lines separating groups of functionality. Lots of spacing wouldn't be popular in the VT100 days, but this is the 21st century and we've got big wide screens now.
Admin
That doesn't look too bad to me. I mean, perhaps the guy figured there may be a future case where someone tries to instantiate everything in a subtly-wrong order, e.g. for code reuse or a test case or something.
Admin
yeah, I do that. It help spot any flow-related errors before i've put more than about 5 minutes into it.
Admin
[dark voice] You underestimate the power of sequence.
x = x + 1; y = x * 10;
is easier than
y = o.f(x)
where o is in another file:
class o { public f ( int i ) { int result = i; result = (i + 1) * 10; return result; } }
Functions, loops and indentation have their place.
Admin
Reminds me of college classes where we had to describe the inputs and outputs of ALL functions. I was always a smartass...
////////////////////////// // Rectangle::GetWidth() // // input: none. // output: The exact value of pi.
int Rectangle::GetWidth(){ return m_iWidth; }
Admin
His comments: // At what point does this.Controller get set and from where? Answer: // Default.aspx.cs invokes the Controller property set method defined above; it // does so from its DisplayPatientSummary() method which is invoked from its // page_load routine. // This works because the page_load method of a page gets invoked before // the page_load method of any controls it contains.
My refactoring of his comments: // NOTE: this.Controller initialized in Default.aspx page_load().
A developer should already know the order of initialization of a page and its contained controls, and if he needs more details he will look at Default.aspx's page_load() and see that it calls the routine DisplayPatientSummary().
Admin
Admin
You have no idea. I've been all the way down to the end of the road and though the gates into the fire pit. I had code reviews with Satan himself.
Imagine it until it hurts, then stop:
If you screw up just one space, the boss starts yelling at you for a minute or more:
} // This is okay
} // This will get you yelled at
I'm not making this up.
Admin
The real WTF are those who take a discussion about commenting techniques and turn it into a VB bash. WTF?
P.S. that was a good WTF regardless of the language. P.P.S. If you need an explanation of what's going on in that sub, you're probably in the wrong field...
Admin
Good god no. The only time you should need comments is to explain the obscure quirks, otherwise your code is poorly factored or you pick stupid method and variable names.
The main drawback of liberally splashing frivolous comments everywhere is that NOONE, EVER keeps them up to date. For that reason alone keep them sparse and just write decent code. Even the //bug 897123 fixed here ones are utterly pointless, that's what version control systems are for.