Re:Indenting.
I saw the post by Hippo at Re: how to get average of matrices' elements?. A few extra comments...

How many spaces to use for each indentation level is actually something that has been academically studied. The answer is "3 or 4 spaces". 2 is too few for good readability and 5 winds up taking up more space while not improving readability. 3 or 4 appear to be almost the same. Certainly 1 is too few. The human eye will just get lost.

To use tabs or not in the code is something that can start a long, very emotional discussion. I personally do not put tabs anywhere in the code or comments.

If you use an editor that is designed to be used for writing code, there will be special features that make it easy to enforce whatever style you prefer. For example, my editor has an option, "convert tabs to spaces". Without doing something special, I can't wind up with any embedded tab characters.

There is a fair amount of variability on the "braces style". One way is like you did it. For Perl code, I prefer to put the initial opening brace on its own line. Like this:

for ($a=0; $a<=2; $a++) { for ($b=0; $b<=2; $b++) { $m_avrg[$a][$b] = ($m_avrg[$a][$b] + $list[$a][$b]); print "$m_avrg[$a][$b] \n"; } }
I find that easier to read. But again, mileage varies a lot! You can make up your own mind about that.

For other languages like Java, I use the more vertically compact form because there winds up being a whole mess of little itty bitty "getters and setters". So I am flexible about this point, depending upon the situation.


In reply to Re: how to get average of matrices' elements? by Marshall
in thread how to get average of matrices' elements? by fasoli

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.