- 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 have seen this before, normally when people dont understand the code that they are writing they use the comments as prompts to remind them what the code is doing...
But really for this, I doubt that anyone would need to many reminders what it was doing.
Admin
The Real WTF is randomly changing pronouns in the middle of a sentence.
Admin
//Add comment "It's like downtown without the pigeons!"
It's like downtown without the pigeons!
Admin
' Add disparaging comment That sucks.
Admin
Admin
Hungarian pirates?
Admin
I've seen developers write comments first and then do the code - I've done it too , usually when I'm writing code on the fly without a spec . might be that ...
Admin
Hell, at least it has comments. Too many f*cktards have 4k line of code classes with 0 comments. I would rather see this than none.
Admin
Indeed, this is a common one. Some people just have to document self-documenting code.
// If the object is null throw a new NullReferenceException if (object is null) throw new NullReferenceException();
Admin
I often start commenting a method/function/whatever and list the steps that need to be implemented. It may look like this:
The code inbetween the comments could even be only one method call. The comments usually stay there. Would this be a bad habit?
Admin
'TODO: add comment to the comment!
Admin
I agree, I've written function bodies in commented pseudo code before and written the code against that.
Looking back on the code, it does tend to lead to bleeding-freaking-obvious comments, thankfully, it usually leads to bleeding-freaking-obvious code as well.
Admin
That's the aproach I'm using for writing my diploma thesis at the moment. The first thing to do for a new chapter is collecting material in the form of comments. :)
Admin
the magic numbers are a much bigger problem than the comments
Admin
I must admit, I do this. I'm an engineer, not a programmer. So to write motion control programs, I find it's easier to open a blank program, write exactly what I want the machine to do in commented lines, then go back and add the code in for each line. I usually just leave the original comments in for future reference in case I ever have to go back to it after working on totally different engineering projects for a while.
It also helps when the variables in the programing language are things like VAR1-VAR255 or a,b...aa,bb, and can't be assigned names. You can name variables in the comments and it helps you figure out what each variable does without going through 3k lines of code. This is especially useful when programming ladder logic.
Of course, as an engineer, I fully expect half the code I've ever written to be posted here by one of my computer science predecessors, though.
Admin
I've seen comments like this that are simply an artifact of design. E.g., an explicit plan:
simply get's commented:
and then only requires coding 'between the comments'! ;)
tmj
Admin
I will rather see code without comments than code commented like this. I once inherited code that looked like a green field (in Visual Studio), with comments such as: //declare i int i;
Anyway, I do think that the comments on the post could be worse. Something like "check that the variable is between 0 and 8". It would be nice to know why the proper range ends in 8, but that's probably documented elsewhere.
Admin
code makes my
head hurt.
Admin
Admin
I just realized this should probably be refactored into a method:
// write the message text WriteMessageText();
Admin
I think they were told to avoid putting input into SQL strings but not how they should do it.
Admin
!WTF.
More comments the better, even if they are "obvious" ones.
Admin
How about the following (in an obscure language but obvious just the same)
// Procedure to set active flag PROCEDURE SET_ACTIVE_FLAG // set the active flag TRUE => ACTIVE_FLAG END //procedure SET_ACTIVE_FLAG
along with the calling code
// set active flag SET_ACTIVE_FLAG()
why??????
Admin
Same here. I often write a bunch of comments - like placeholders - to get the flow and then go back and add the code. I may or may not remove the comments afterwards.
Admin
These comments not half as bad as comments that start with "TODO" that have been in the code for 4 years with the programmer who wrote it long gone.
Admin
The sad thing is alot of people think their code is "intuitive" and it is not. I'd rather have to many comments than non at all. Alot of young people thing "it is obvious" what their code is doing. Sorry, you are wrong in many cases. What usually results is a furious effort to find out what variables a, i and z are doing elsewhere in the code.
Self documenting code is often self documenting, but it is simply true that for every 5 SLOC, there should be atleast one comment.
This is a horrible dailyWTF as it is simply an example of what you young (sometimes arrogant) people need to learn how to do in the real world. Just wait 5-10 years for someone to tell you that your code needs updating and when you look at it you don't know what it is doing.
Admin
A hidden WTF: in the code example, there's no way to be sure that the messages will be retrieved in the correct order (or in fact the right number), so the message shown through the array could be totally wrong. Nice.
Admin
I would be more inclined to do it this way: public void doWhatIsNeeded { connect(); x = getData(); processData(x); cleanUp(); }
The code is now self-documenting - the method names replace the comments.
The problem I have with too many comments is that people change the code, but they dont update the comments,. This leads to comments saying one thing, with code doing another, and actually hindering your code. Some comments are o.k. for complex code blocks, and also for documenting public methods, and especially interfaces you expect other people to implement, such as in a framework. Generally speaking, most code should be readable and understandable without comments.
Admin
Regarding the "why" of testing the range first, and then querying using the same range: if the id is out of range, you save a round trip to the database. As was pointed out in a previous comment, he/she should have used constants for the range. I'd rather see code like this any day than code with no comments at all.
Admin
This complaint is just flat-out wrong. Clearly from the comments, I am not the only one here who writes pseudocode in the form of comments, then codes to the comments. I also doubt much of my efforts would appear on this site.
If you don't like the commentary style, tough. I think the effort would be better focused on code, not comments.
Admin
umm... the code above needs updating now, not 5-10 years from now.
either that or IHBT =/ case in point:
Admin
he's probably just a new programmer who is still used to CS classes that require one to write comments on basic functionality as well as the reason something is written. honestly, i think it is a good idea. this is really simple code, but what if the spirit were to suddenly descend on him and he busts out a chain of voodoo that is honestly cool? at least he would have the need to tell us mere mortals what it does explicitly rather than some nebulous "i need to make sure the thing is the right other thing" that we all see too often when code is documented poorly.
Admin
In other words, commenting should be done with intelligence, just like coding.
Admin
Looks more like someone wrote the comments to pseudo-code the routine they were going to write and then filled in the code later.
CAPTCHA: acsi - urban ascii
Admin
Admin
We are frequently plagued by another kind of comment. The LIAR.
Admin
sadly, many programmer in the last 4 years asked me to write comments like that... which i never did because for me it would be hard to maintain 2 side of thing, codes and comments...
Admin
Maybe they are engineering a time machine. Maybe the only mistake was that they just gave it away!
Admin
Well, it's better than some of the comments in the xt:Commerce Source:
create_account.php:201: //don't know why, but this happens sometimes and new user becomes admin
Admin
A ex-colleague would have expanded that, to make it even more supportable:
// write the message text WriteMessageText(); Log("Have written message text");
(Now imagine a class where in some methods every line looks like that)
Admin
Now that's a legitimate complaint for this style of commenting. You'd hate to see something like this:
// Add one to x x--;
Admin
100% agreed. I do this, directly before writing the actual connect getDAta processData and cleanup methods.
Admin
How 'bout successors?
Admin
This is how it should be:
// Increment i by one, because i needs to be incremeted by one here i=i+1;
Admin
This is no WTF. Some poor comments? Seriously? If you don't have anything worth posting, don't post.
Admin
Sounds like a Beatles song: There's nothing you can do that can't be done There's nothing you can sing that can't be sung
Admin
// Follow all the other idiots who have inevitably said, "Comment on this post"
Admin
// Follow all the other idiots who have inevitably said, "Comment on this post"
Admin
//Start thinking of a witty comment to be posted on //the featured comments that mimics part of the article string strComment = String.Empty;
//Spend more time thinking instead of actually working Thread.Sleep(900);
//Start writing out comment strComment = GenerateDesperatePleaForAttention();
//Submit your comment SubmitComment();
//If you're lucky enough people might quote your comment bool anyoneCares = true;
while(anyoneCares) { Smile();
//No one will care about this after a day if(DailyWTF.Articles.TheHowNotTheWhy.AgeInHours > 24) { anyoneCares = false; } }
Cry();
Admin
In the previous weeks, I've come to love anything beyond the auto-generated method comment.
The only comments seen so far is programmer's name and lots of logger info like "Inside contr", "inside low".
Drinking away the pain works for a while.