Initially my answer was going to be "It depends on the size and complexity of the code" but then I stopped and thought for a moment.

If a program contains subroutines, then it is a fairly safe bet that it is big or complex enough to require comments. After all, very few people use a subroutine in a 3 line program. ;)

If it doesn't all fit on my screen without scrolling, then adding comments provides visible breaks in the code making it easier to find a specific section.

So basically I add at least one comment to each subroutine (stating what it does on a single line) to make it easier to spot if and when the program gets larger.

If I used some really hairy code - or something just plain weird - I'll add more detail, though not to extremes.

I find it makes life easier that way - especially if I have to edit the code several months later or decide to reuse that subroutine elsewhere.


In reply to Re: Documenting Methods/Subs by Wysardry
in thread Documenting Methods/Subs by vek

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.