• devy (unregistered)

    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.

  • (cs)
    Jake Vinson:
    Often, the way one learns to do something is the way they keep doing it...

    The Real WTF is randomly changing pronouns in the middle of a sentence.

  • (cs)

    //Add comment "It's like downtown without the pigeons!"

    It's like downtown without the pigeons!

  • (cs)

    ' Add disparaging comment That sucks.

  • (cs)
    arrMsg
    Is it "Talk Like a Pirate" day already?
  • monkeyPushButton (unregistered) in reply to Code Dependent
    Code Dependent:
    arrMsg
    Is it "Talk Like a Pirate" day already?

    Hungarian pirates?

  • UriGagarin (unregistered)

    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 ...

  • (cs)

    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.

  • Anonymous (unregistered)

    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();

  • Whoevar (unregistered)

    I often start commenting a method/function/whatever and list the steps that need to be implemented. It may look like this:

    public void doWhatIsNeeded {
      // Step 1: connect
      // Step 2: request data X
      // Step 3: for each X do Y
      // Step 4: finish, clean up
    }
    

    The code inbetween the comments could even be only one method call. The comments usually stay there. Would this be a bad habit?

  • Sandor (unregistered)

    'TODO: add comment to the comment!

  • Tris (unregistered) in reply to UriGagarin

    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.

  • Haf (unregistered) in reply to UriGagarin

    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. :)

  • (cs)

    the magic numbers are a much bigger problem than the comments

  • Josh (unregistered)

    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.

  • tmj (unregistered)

    I've seen comments like this that are simply an artifact of design. E.g., an explicit plan:

       (1) Do A
       (2) Do B
       ...
       (N) Return Z

    simply get's commented:

       // Do A
       // Do B
       ...
       // Return Z

    and then only requires coding 'between the comments'! ;)

    tmj

  • Osno (unregistered) in reply to amischiefr

    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.

  • sota (unregistered) in reply to Tris
                               Reading through badly indented 
    

    code makes my
    head hurt.

  • (cs) in reply to Josh
    Josh:
    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.
    Doubtless you meant to say "postdecessors".
  • sota (unregistered)

    I just realized this should probably be refactored into a method:

    // write the message text WriteMessageText();

  • Alan (unregistered)

    I think they were told to avoid putting input into SQL strings but not how they should do it.

  • bored (unregistered)

    !WTF.

    More comments the better, even if they are "obvious" ones.

  • Kanitatlan (unregistered)

    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??????

  • lanmind (unregistered)

    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.

  • EatenByAGrue (unregistered)

    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.

  • SatanClaus (unregistered)

    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.

  • Bo (unregistered)

    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.

  • Jimbobzo (unregistered) in reply to Whoevar
    Whoevar:
    I often start commenting a method/function/whatever and list the steps that need to be implemented. It may look like this:
    public void doWhatIsNeeded {
      // Step 1: connect
      // Step 2: request data X
      // Step 3: for each X do Y
      // Step 4: finish, clean up
    }
    

    The code inbetween the comments could even be only one method call. The comments usually stay there. Would this be a bad habit?

    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.

  • Willy (unregistered)

    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.

  • Glenn Lasher (unregistered)

    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.

  • sudo make me a sandwich (unregistered) in reply to SatanClaus
    SatanClaus:
    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.

    umm... the code above needs updating now, not 5-10 years from now.

    either that or IHBT =/ case in point:

    SatanClaus:
    Self documenting code is often self documenting, but it is simply true that for every 5 SLOC, there should be atleast one comment.
  • the amazing null (unregistered)

    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.

  • (cs) in reply to SatanClaus
    SatanClaus:
    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.
    I strongly disagree, and I've been programming professionally for 25 years. The point of the WTF, which you seem to have missed, is that the comments that are there are *useless* while a desperately needed comment is missing.

    In other words, commenting should be done with intelligence, just like coding.

  • Tom Welch (unregistered)

    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

  • (cs) in reply to SatanClaus
    SatanClaus:
    Self documenting code is often self documenting, but it is simply true that for every 5 SLOC, there should be atleast one comment.
    The problem with hard rules is that they run up against smartasses who do things like
       //Add a mandatory comment here to keep my boss off my back
    and other equally daft things. Low level coding standards are mostly useless; much better to have high level ones like “every function must have a human-readable description of its intended behavior”. Better yet, tell programmers why this sort of thing is important and involve them in the maintenance of their own code...
  • MooseBrains (unregistered)

    We are frequently plagued by another kind of comment. The LIAR.

    /**
     * This method just returns true for now.
     * @return always true
     */
    public boolean hasMooseBrains() {
        return false;
    }
  • anonym (unregistered)

    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...

  • Anon (unregistered) in reply to Code Dependent
    Code Dependent:
    Josh:
    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.
    Doubtless you meant to say "postdecessors".

    Maybe they are engineering a time machine. Maybe the only mistake was that they just gave it away!

  • whoever (unregistered)

    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

  • MooseBrains (unregistered) in reply to sota
    sota:
    I just realized this should probably be refactored into a method:

    // write the message text WriteMessageText();

    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)

  • Anon (unregistered) in reply to Jimbobzo
    Jimbobzo:
    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.

    Now that's a legitimate complaint for this style of commenting. You'd hate to see something like this:

    // Add one to x x--;

  • aaawww (unregistered) in reply to Jimbobzo
    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.

    100% agreed. I do this, directly before writing the actual connect getDAta processData and cleanup methods.

  • Crash Magnet (unregistered) in reply to Code Dependent
    Code Dependent:
    Josh:
    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.
    Doubtless you meant to say "postdecessors".

    How 'bout successors?

  • (cs)

    This is how it should be:

    // Increment i by one, because i needs to be incremeted by one here i=i+1;

  • Calvin Spealman (unregistered)

    This is no WTF. Some poor comments? Seriously? If you don't have anything worth posting, don't post.

  • (cs) in reply to SatanClaus
    SatanClaus:
    Self documenting code is often self documenting
    Ya think?

    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

  • idfk (unregistered)

    // Follow all the other idiots who have inevitably said, "Comment on this post"

  • idfk (unregistered)

    // Follow all the other idiots who have inevitably said, "Comment on this post"

  • (cs)

    //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();

  • ClutchDude (unregistered)

    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.

Leave a comment on “The How, Not the Why”

Log In or post as a guest

Replying to comment #243393:

« Return to Article