Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-26 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found