I've changed my style of commenting many times (as many times as I have changed my style of coding).

I have found that if I write clear code and use meaningful variable names comments are fairly unnecessary. This is not to say that I shouldn't comment the code anyway, because what is clear and meaningful to me may not be to someone else.

What I have found extremely handy is commenting the ends of my blocks and subroutines if they are more than a few lines apart. For me finding the ends makes life easier (and the ends normally don't change).

if ($some_id eq "somthing"){# beginning of some_id ... do lots of meaningful and impressive things here for my $i (0 .. 10){ do something brief here } } else { # else of some_id &a_really_descriptive_thingy; } # end of some_id .... sub a_really_descriptive_thingy { ....something fun happens here } # end of a_really_descriptive_thingy
One thing I have stopped doing is commenting my code with poetry, jokes and completely meaningless bits.

I still get my chops busted for one comment I made in the middle of a fairly routine script.

# Reset Alien Receptor Beam!

The guy spent an hour trying to find it to reset it...:)

EEjack


In reply to Re: The difficulties of commenting code by eejack
in thread The difficulties of commenting code by Henri Icarus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.