Slashdot Mirror


How to Write Comments

Denis Krukovsky writes "Should I write comments? What is a good comment? Is it possible to comment a class in 5 minutes? See " Everybody knows that good code is self documenting- which is why my prof in college demanded we write in Ada. I instead suggest commenting in haiku.

33 of 556 comments (clear)

  1. Reading by Southpaw018 · · Score: 5, Funny

    Code should read easy Like many Slashdot comments See? It's not so hard.

    --
    ACs are modded -6. I don't read you, I don't mod you, I don't see you. Don't like it? Don't be a coward.
    1. Re:Reading by Southpaw018 · · Score: 5, Funny

      *grumble* Forgot the
      s.

      Code should read easy
      Like many Slashdot comments
      See? It's not so hard.

      --
      ACs are modded -6. I don't read you, I don't mod you, I don't see you. Don't like it? Don't be a coward.
    2. Re:Reading by The+Famous+Brett+Wat · · Score: 2, Funny

      A race for karma
      Carelessness surely follows
      Always preview first

      --
      proof, n. A demonstration that a conclusion is implied by certain premises and axioms.
    3. Re:Reading by meringuoid · · Score: 5, Funny

      Post with bad format
      Then rewrite it correctly
      Get double karma

      --
      Real Daleks don't climb stairs - they level the building.
    4. Re:Reading by meringuoid · · Score: 5, Funny
      * bah *

      My haiku is rotten
      I hang my head in sorrow
      Forgot the season.

      --
      Real Daleks don't climb stairs - they level the building.
    5. Re:Reading by bgalbrecht · · Score: 5, Funny

      Karma is quite nice
      But funny gets no karma
      Snow falls slowly here

    6. Re:Reading by Sax+Maniac · · Score: 2, Funny
      I hate one-liners. Here's a fake example of stuff I see all the time:

      if (foo) { /* OHO! */
      if (bar) return; /* Well, well, false alarm. */
      if (!x) /* Class is bogus. */
      z=y; /* Did we already have one? */
      }
      Great, I'm sure this Howard-Cosell running commentary is cute if you already know what the code is doing, but it means nothing to everyone else. Comments are not for you, they are for other people.
      --
      I can explanate how to administrate your network. You must configurate and segmentate it, so it can computate.
    7. Re:Reading by dgatwood · · Score: 2, Funny
      This method is the
      winter of our discontent.
      Hell freezeth over.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

  2. Comments by LiquidCoooled · · Score: 5, Funny


    <!-- why don't they ever RTFA? -->
    <b>Nothing for you to see here. Please move along.</b>

    --
    liqbase :: faster than paper
    1. Re:Comments by Golias · · Score: 5, Funny

      /*
      This is my comment. There are many like it, but this one is mine.

      My comment is my best friend. It is my life. I must master it as I must master my life.

      My comment, without me, is useless. Without my comment, I am useless. I must author my comment true. I must write clearer than my code which is trying to obfuscate my efforts. I must comment in before it gets me fired. I WILL...

      My comment and myself know that what counts in this job is not the lines we write, the size of our file, nor the time to compile it. We know that it is the completed change requests that count. WE WILL COMPLETE...

      My comment is human, even as I, because it is my life. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its words, its letters, its punctuation and its opening & closing tags. I will ever guard it against the ravages of re-edits and cruft as I will ever guard my legs, my arms, my eyes and my heart against damage. I will keep my comment clean and ready. We will become part of each other. WE WILL...

      Before God, I swear this creed. My comment and myself are the defenders of my department. We are the masters of our code. WE ARE THE SAVIORS OF MY LIFE.

      So be it, until the beta goes gold and there are no further patch requests, but sales!

      --

      Information wants to be anthropomorphized.

    2. Re:Comments by Golias · · Score: 4, Funny
      Oh... and this is a closing tag for my comment. ---> */

      // I guess I should have used one-liners.

      --

      Information wants to be anthropomorphized.

  3. A bad question... by Snamh+Da+Ean · · Score: 2, Funny

    Asking Slashdot "Should I post comments?" is a bit like asking turkey's "Should we cancel Christmas?".

    Let the commencement of the comment posting beginulate!

  4. cenqua! by i.r.id10t · · Score: 5, Funny

    Simple, and I've posted this link a few times before, but you really need to use cenqua. Takes all the pain out of comments, and still allows personality quirks to show thru.

    The Commentator

    Just be careful on your settings and you should be fine.

    --
    Don't blame me, I voted for Kodos
    1. Re:cenqua! by Anonymous Coward · · Score: 4, Funny

      Slashdot really needs a "-1, joke went lightyears over his head" moderation option.

  5. Comment every conditional branch or loop by Matt+Ownby · · Score: 4, Funny

    I once read that a good comment will appear on every conditional branch or loop, and a good comment will also state the INTENTION for doing something, rather than what is actually being done (because the programmer can usually figure out what is being done). For example: // i starts at 1 instead of 0 because we don't want to process the application's name (first argument)
    for (int i = 1; i argc; i++)
    {
        printf("ARgument is %s\n", argv[i]);
    } // AND with 0xFF1234 because that is the first set of bytes in the file header
    if (u & 0xFF1234)
    {
        printf("File is valid.\n");
    } // say file not found instead of invalid due to reason blah blah blah ...
    else
    {
        printf("File not found.\n");
    }

    1. Re:Comment every conditional branch or loop by KilobyteKnight · · Score: 4, Funny
      // say file not found instead of invalid due to reason blah blah blah ...
      "blah blah blah" is mostly what I use for comments also :)

      --
      When will Windows be ready for the desktop?
    2. Re: Comment every conditional branch or loop by Black+Parrot · · Score: 5, Funny

      > I once read that a good comment will appear on every conditional branch or loop

      But be sure to put them outside the loop, so people won't have to read them over and over.

      --
      Sheesh, evil *and* a jerk. -- Jade
  6. Sure by Praetorian42 · · Score: 3, Funny

    Sure my code is readable, but more often than not I find my comments explaining the screwed up business logic behind the code.

  7. Words to live by by 3CRanch · · Score: 5, Funny

    During college I always lived by:

    "It was hard to write; it should be hard to read"

    'course the profs didn't appreciate that much...

  8. Haiku? by Daedala · · Score: 3, Funny

    Remember the seasonal reference!

    Begin declaring
    Global integers, constant
    As the winter rain

    Check for null values
    That will cause problems later
    Cherry blossoms fall

    --
    What I say does not represent the views of my employers, my friends, my cats, or myself.
  9. /* Drunk -- fix later */ by Cobalt+Jacket · · Score: 2, Funny

    © Leo Plotkin

  10. Humour in the Linux kernel by Mr_Silver · · Score: 4, Funny
    This made me smile (in a rather sad way)...
    static void happy_meal_tcvr_write(struct happy_meal *hp, unsigned long tregs, int reg, unsigned short value)
    {
    int tries = TCVR_WRITE_TRIES;

    ASD(("happy_meal_tcvr_write: reg=0x%02x value=%04xn", reg, value));

    /* Welcome to Sun Microsystems, can I take your order please? */
    if (!hp->happy_flags & HFLAG_FENABLE)
    return happy_meal_bb_write(hp, tregs, reg, value);

    /* Would you like fries with that? */
    hme_write32(hp, tregs + TCVR_FRAME, (FRAME_WRITE | (hp->paddr
    Mind you, it's not a comment but this one was good for printer status:
    static char *usblp_messages[] = { "ok", "out of paper", "off-line", "on fire" };
    --
    Avantslash - View Slashdot cleanly on your mobile phone.
  11. Re:The why not the how by op12 · · Score: 5, Funny

    What about doing this?

    /* makes it public */ public /* boolean value */ bool /* function name */ CheckSmsValue( /* function parameters */Account smsAccount)
    /* start function */{
    /* Comment */
    // Check tarriff is null
    /* if statement */
    if ( /* variable */ Account.Tarrif /* equals */ == /* Null */ null)
    /* return */ return;
    /* dot, dot, dot */ ...
    /* end function */}

  12. Are you certain this is what you want? by palad1 · · Score: 2, Funny

    public void GNAAT()
            {
                System.IO.Stream stream = System.Net.HttpWebRequest.Create("http://www.goats e.cx/receiver.jpg").GetResponse().GetResponseStrea m();
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream, false);
                stream.Close();
                System.Windows.Forms.Form form = new System.Windows.Forms.Form();
                form.BackgroundImage = bmp;
                form.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                form.Disposed += delegate(object src, EventArgs args)
                {
                    GNAAT();
                };
                form.Show();
            }

    // A moose once bit my sister. You see, she was carving her initials in the moose with a toothbrush when...

  13. Re:Haiku Commenting? by p2sam · · Score: 5, Funny

    The 1st rule of software engineering is: you do not put hacks in your projects
    The 2nd rule of software engineering is: you DO NOT put hacks your projects
    The 3rd rule of software engineering is: document you hacks
    The 4th rule of software engineering is: one hack at a time
    The 5th rule of software engineering is: if this is your first project, you'd have to do lots of hacks. :)

  14. Unified theory of commenting by awtbfb · · Score: 5, Funny
    // If you can't follow this, go ask CowboyNeal
  15. My haiku by timbck2 · · Score: 4, Funny

    So many good posts --
    Damn! I wish I had mod points!
    Better luck next time.

    --
    Absurdity: A statement or belief manifestly inconsistent with one's own opinion. -- Ambrose Bierce
  16. Re:Haiku Commenting? by chihowa · · Score: 2, Funny

    Maybe I'm just not getting the joke, but if upon re-inspection you don't understand what you were doing and why, how do you come up with the comments to add to it?

    --
    If you want a vision of the future, imagine a youtube comments section scrolling - forever.
  17. I have to tell this story... by RetiredMidn · · Score: 4, Funny
    ...if I haven't already.

    Back in the 70's, I worked the Help Desk at my college's computer center. I was approached by a student taking the entry-level programming class, which taught FORTRAN; programs for the class were written on punched cards (!) and submitted to our RCA Spectra for batch processing.

    Anyway, this guy came to me with a question about a cryptic compiler error message (maybe that's redundant). I asked to look at his listing, and found the problem easily enough, but I was intrigued to see that his code was double spaced! (See it coming, yet?) I wanted to figure out how he did it, because I thought it would be useful in my own work to leave room for writing notes on my listings when I looked at them back in my dorm room.

    I couldn't find any special options on his command card (the first card in the deck that specified how the deck was to be processed; I finally realized that every other line was a blank comment line. (A "C" in column one, and nothing else on the line/card, for you young'uns).

    I couldn't imaging taking the time at the card punch to type just "C", then feed a new card (which took a couple of seconds) between every line of code, so I asked him why he had bothered.

    His answer...

    [...wait for it...]

    "The professor said the program would be easier to debug if we included a lot of comments."

    P.S. The program, about 15-20 lines long, was devoid of actual comment text.

  18. At least in C the rule is by washley · · Score: 2, Funny

    "If it was hard to write it should be hard to read."

  19. Re:One good reason by f0rtytw0 · · Score: 2, Funny

    As my professor once told us "Write code so that your pyschotic successor does not hunt you down and kill you."

    --
    this is the most important sig ever! In your face 446154!
  20. indeed, but to be both traditional & slashdott by Phil+Urich · · Score: 2, Funny

    Soviet Russia
    "Season mention" comments you
    In Winter: Profit

    --
    I remember sigs. Oh, a simpler time!
  21. Is that you?! by kentyman · · Score: 2, Funny

    //
    Midn, is that you?
    //
    I haven't seen you in like 30 years!
    //
    How've you been?!
    //

    --
    You know where you are? You're in the $PATH, baby. You're gonna get executed!