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??
Hopefully most of the time. :-)

Seriously I find that my average function is about 10 lines. Some are shorter - a lot shorter. A few are much longer. But that seems to be an average for me.

Here is a list of reasons from chapter 5 of Code Complete to think about. I won't copy explanations, just the reasons:

  1. Reducing complexity
  2. Avoiding duplicate code
  3. Limiting effects of changes
  4. Hiding sequences
  5. Improving performance (optimize later)
  6. Making central points of control
  7. Hiding data structures
  8. Hiding global data
  9. Hiding pointer operations
  10. Promoting code reuse
  11. Planning for a family of programs
  12. Making a section of code reusable
  13. Improving portability
  14. Isolating complex operations
  15. Isolating use of non-standard language functions
  16. Simplifying complicated boolean tests
I have found that all of these benefits still hold in Perl. Well performance is usually hit a little, but you are left in a position to optimize where it counts later. And you shouldn't have non-standard language functions. But in practice I have noticed portability issues from time to time.

So while that list doesn't hold perfectly for Perl, it is still generally on target.

Note that in particular comments explaining what you intended at one point are not a good substitute for clear code. Should you change the code later, the comments will often remain to confuse you. Also deeply nested loops may not take many lines, but they make it much harder to separate the forest from the trees.


In reply to Re (tilly) 1: When do you function? by tilly
in thread When do you function? by zdog

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 imbibing at the Monastery: (6)
As of 2024-03-28 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found