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
- Reducing complexity
- Avoiding duplicate code
- Limiting effects of changes
- Hiding sequences
- Improving performance (optimize later)
- Making central points of control
- Hiding data structures
- Hiding global data
- Hiding pointer operations
- Promoting code reuse
- Planning for a family of programs
- Making a section of code reusable
- Improving portability
- Isolating complex operations
- Isolating use of non-standard language functions
- 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
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||