Slashdot Mirror


Successful Strategies for Commenting Your Code

LilG writes "Over at Particletree, Ryan Campbell writes about Successful Strategies for Commenting Your Code. His essay gives advice and examples on proper commenting, and details some different strategies."

26 of 500 comments (clear)

  1. Huh? by tntguy · · Score: 5, Funny

    These comments you speak of, they seem foreign and strange to me.

    1. Re:Huh? by bluelip · · Score: 3, Funny

      "The code was hard to write. The code should be hard to read."

      Was that some form of early DMCA or IP lockdown?

      --

      Yep, I never spell check.
      More incorrect spellings can be found he
    2. Re:Huh? by TommydCat · · Score: 2, Funny

      /* Please phrase your reply in the form of a comment. */ /* Thank you */

      --
      This comment does not necessarily represent the views and opinions of the author.
    3. Re:Huh? by torpor · · Score: 2, Funny

      /*
        * slashdot comment comment
        * 1.0.0 - torpor - init.
          */

      #pragma KARMA_HACK // technically, also a comment. /* comments are fun. */ //code goes here..

      --
      ; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
    4. Re:Huh? by MHobbit · · Score: 4, Funny

      A TRUE Klingon warrior does not comment his code!

      *ducks*

      --
      Debugging? Klingons do not debug. Bugs are good for building character in the user.
    5. Re:Huh? by Kehvarl · · Score: 2, Funny

      *ducks*

      A true Klingon warrior does not duck.

      A true Klingon warrior would have nothing to do with such a weak waterfowl.

    6. Re:Huh? by not-enough-info · · Score: 2, Funny

      The user catalog is a perl database and we need to localize for how many countries? Then, today is a good day to die!

      --
      ---k--
      </stupid>
    7. Re:Huh? by hhlost · · Score: 2, Funny

      // TODO: add comments

  2. My favorite code comment not written by me by dcarey · · Score: 4, Funny

    I was doing some maintenance on someone else's code and came across this nasty set of like 8 nested if/elses. It was a bloody horrible hack. But the best part of all was the comment right at the top: /* Oh, fuck */

    --

    -- (Score:i , Imaginary)

    1. Re:My favorite code comment not written by me by lukewarmfusion · · Score: 4, Funny

      So you found that, eh? *evil chuckle*

      I was in a similar spot a month or two ago and found some other company's comments - unhelpful as always - in the form of typed out sound effects.

      # This function goes vroooooooommm-pop!

      I have no idea why the developers put such comments there other than to entertain themselves as they sifted through their horribly written Perl.

  3. Don't do it! by Anonymous Coward · · Score: 0, Funny

    Don't EVER comment your code if you work for a company. That's a sure fire way to lose your job! If you don't comment your code then you are the only person who can understand it, making you indispensible.

    In summary, DON'T COMMENT!

  4. Gotta say it by modi123 · · Score: 2, Funny

    /* no */

  5. Example by dduardo · · Score: 3, Funny

    /*This loop starts at x is equal to 1 and continues while x is less then 5. x is incremented by 1 each time.*/ for( int x=1; x5; x++ ) { printf("Hello World\n");/*Prints "Hello World"*/ }

  6. Practice what you preach by ChrisF79 · · Score: 5, Funny

    I viewed the source on the site and nothing was commented :)

    --
    Finance tutorials and more! Understandfinance
  7. Comments are more important than Code? by jetkust · · Score: 4, Funny

    Comments are more important than Code?

    I once tried writing code that was completely made up of comments. It was easy to write and all, but didn't work very well.

    1. Re:Comments are more important than Code? by NialScorva · · Score: 4, Funny

      At least you had no compile errors or core dumps, and I bet you didn't have any exploitable vulnerabilities either.

  8. Don't comment by i.r.id10t · · Score: 5, Funny

    Don't comment at all, and just run it thru The Commentator!

    http://www.cenqua.com/commentator/

    --
    Don't blame me, I voted for Kodos
  9. No by rbarreira · · Score: 5, Funny

    No, that first one should be something like:

    This loop starts at 1, and to 5 it counts. It doesn't count to 6, nor it does count to 8. It does not count to 3 or 4, except in passage to 5. When it reaches number 5, the fifth number...

    --

    The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    1. Re:No by lboxman · · Score: 2, Funny

      That's only appropriate if you're documenting python code...

      --
      Regexes are like cocaine. The first hit is pretty good, but afterwards you try to use them to solve all your problems.
    2. Re:No by legirons · · Score: 3, Funny
      Not in the real world... more like:
      //----------
      // ReadSalaryData - reads table of salary values from database
      // Parameters:
      // - DB, database handle
      // - Data, pointer to list
      // Returns: Success
      //---------
      void DeleteUsername(char *Name)
      {
      ...
  10. Things to always remember when commenting by WillAffleckUW · · Score: 4, Funny

    1. Never spelchezk.
    2. Use randomly chosen variable names, or objects that resemble your favorite Orcs and Trolls from LotR - after all, everyone knows that a Lothlorien object will have farseeing ability, so it's obvious.
    3. When instantiating something for the first time, never explain it - real programmers read the original object source.
    4. If you do something complex, write a short pithy comment like /* magic occurs */
    5. If you do something easy but you were drinking too much hot cocoa, write a long verbose description, and also mention how good the hot cocoa was.
    6. Always include song lyrics to what you're listening to while you wrote the code.
    7. Object inheritence means never having to explain the code.
    8. Repetition is the best way to reinforce obvious things - so repeat the obvious thing since it's the best way to reinforce it.
    9. If you break up with your girl/boyfriend, write about it in the comments - people really want to know.
    10. If you're updating or modifying code, write your opinion about the original code in the comments. Use nasty words if you can.

    --
    -- Tigger warning: This post may contain tiggers! --
    1. Re:Things to always remember when commenting by Reverend528 · · Score: 2, Funny
      haikus or other poems are also useful comments:

      // nested switch statments
      // with some inefficient code
      // and memory leaks

  11. All Depends... by eno2001 · · Score: 3, Funny
    ...on who is going to be reading the code after you are gone. Sadly, due to differing levels of expertise, there is no optimum method of commenting code. For some, this is a very useful comment (I'm using pound sign comment designation as an example):

    # The main function starts here

    or...

    # This is a loop and it will run while a certain
    # condition exists.

    or...

    # Don't forget to remove this section after
    # I'm gone - Dan - 04/25/1995

    Think about the children! ;P

    --
    -"...bad old ideas look confusingly fresh when they are packaged as technology" - Jaron Lanier (Digital Maoism on Edge.o
  12. Next on his list of things to write about by deblau · · Score: 2, Funny

    Successful Strategies for Crashing Your Website

    --
    This post expresses my opinion, not that of my employer. And yes, IAAL.
  13. Obfucksucated code contest by jurt1235 · · Score: 2, Funny

    This kind of reviews are really destructive for my goal of winning the obfuscated code contest (http://www.ioccc.org/ can not read any further.

    --

    My wife's sketchblog Blob[p]: Gastrono-me
  14. Re:Klingons and code documentation by tomhudson · · Score: 2, Funny
    1. Our users will know fear and cower before our software. Ship it! Ship it, and let them flee like the dogs they are!
    Bill Gates is a Klingon? I thought he was a Borg?