On 4/9/06, Adam W <[EMAIL PROTECTED]> wrote:

> I was wondering when it is appropriate to do multiple shifts on
> parameters passed to a subroutine and when it is appropriate to just
> feed it @_.

Whatever makes the most sense to the programmer in the given
situation, usually. TMTOWTDI in Perl, and part of the reason for that
is that one method or the other seems more natural. Sometimes you
shift, sometimes you access @_ directly, sometimes you copy it to
variables.

If you're worried about efficiency, benchmark; but run-time efficiency
should rarely be the way to make these decisions. The tiny bit of
run-time involved is likely dwarfed by the internal overhead of the
subroutine call itself. And that's not counting the cost of whatever
operation the subroutine is meant to do; the payload is often many
many orders of magnitude more.

I said above that your target shouldn't be run-time efficiency in this
case, because it hardly makes a difference. In most cases, once you've
got a correct algorithm in mind, what you want to optimize is
*programmer* efficiency. By coding in the way that makes the most
sense, you'll spend less time writing it, and your maintenance
programmer will take less time to read, debug, and maintain it.
Myriads of clock cycles are cheap, but programmer hours are expensive.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to