Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, a lot of good replies have already been offered, but when has that stopped me?

A simple thing to remember is that a section of code should be no longer than a person is willing to read at a time. A person earlier suggested about one page. The exact length may vary, and depends on specific needs. BUT, remember that if someone else has to come in and read it (or you, a while after you wrote it--which brought us this question :) SO, you should make the logic of the code flow. If your function is getting too long and you're finding yourself scrolling up and down to find out something about it, you're probably better off to make some sub-functions(ha; thinking of perl, that's kind of redundant).

If there's a function that's calling too many small functions, there are several possibilities.
(1)Not worry about it
(2)Combine some of them
(3)Make a function that's only job is to call them

To explain point three: if, for example, you have some complex data types that you need to have the user initialize, and your code looks like this:

$var1 = init_var1(); $var2 = init_var2(); $var3 = init_var3(); ...var4, etc...
Then what you could do is this:
($var1,$var2,$var3,..etc.) = init_all_variables();
init_all_variables() could just be a function that calls the init_varX functions. This method is very useful when it is needed.

In reply to Re: To sub or not to sub, that is the question? by dimmesdale
in thread To sub or not to sub, that is the question? by tachyon

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 meditating upon the Monastery: (4)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found