I agree with all your points with a slight rephrasing to the first point. How about 'use references when they are the best solution to the problem'. Consider the following benchmark.
use Benchmark; my @big_array = (1 .. 10000); sub ret_array { return @big_array; } sub ret_ref { return \@big_array; } timethese(10000, { 'return_array' => sub { my @array = ret_array(); }, 'return_ref' => sub { my $array_ref = ret_ref(); } });
Which yeilds:
Benchmark: timing 10000 iterations of return_array, return_ref... return_array: 120 wallclock secs (117.82 usr + 1.65 sys = 119.47 CPU) return_ref: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU)
Returning the reference is faster since it doesn't have to copy each element, allocate memory for it, etc. Granted it can make your code more cryptic, but in the cases where the returned array is large, or the subroutine is called often, the speed increase is well worth it.

/\/\averick


In reply to RE: My philosophy on coding (in Perl and other languages): by maverick
in thread My philosophy on coding (in Perl and other languages): by mrmick

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.