Casey,

I think you answered my question, but I see, in reading my post, that I didn't cover everything I intended in my question.

For example, neither of those docs really explains to the novice programmer the value of code modularization. I'm not just referring to placing reused code in a library. Even within one script, you'll often see people write a subroutine that is named something like "&get_grades" and when you look at the subroutine, it will have all sorts of functionality not related to getting the scores.

Let's say the &get_grades subroutine takes two arguments: the student and the class. One thing we might want to do is verify that the person running the script has the right to view those grades. Oftimes, you'll see such validation occur directly in the &get_grades subroutine. It really doesn't belong there as it is not directly related to the function of that subroutine. The authorization should probably take place before the subroutine call, or the &get_grades should call another subroutine like &verify_access_rights. That's second nature to many of us, but may not be immediately obvious to the novice.

Another issue would be code optimization. For many common functions, there are a lot of things we can do to optimize the code. In my orginal post, I mentioned the difference between

$array[$index++] = $_;
and
push (@array, $_);
The second version is preferable in terms of optimization. Regexes are another great area where common optimization rules can be grouped and demonstrated. For example, virtually everyone knows that $` is a bad thing. But, how many people really pay attention to /o and /i switches? <CODE> while (<>)

In reply to RE: RE: Good coding practices by Ovid
in thread Good coding practices by Ovid

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.