develooper Front page | perl.beginners | Postings from May 2012

Re: shift vs @_

Thread Previous | Thread Next
From:
Steve Bertrand
Date:
May 21, 2012 13:32
Subject:
Re: shift vs @_
Message ID:
4FBAA652.6080108@gmail.com
On 2012-05-21 14:12, sono-io@fannullone.us wrote:
> Hi Paul,
>
>> Please don't care about this until your code is running correctly but
>> too slowly and profiling has determined that this is the bottleneck.
>
> 	I'm curious as to why you say this.  If one way is faster than another, wouldn't it be better to do it that way, as long as it doesn't cause any problems?
>
> 	BTW, my code is running correctly.  I'm refactoring an old script.  The way I see it, every little bit helps. =;)

A slight sacrifice in speed is much better than a lack of clarity or 
problematic code, unless of course your code's speed is critical. What 
Paul is saying is that it's common not to focus a whole bunch on 
sub-millisecond performance gains like this, and when you do, it'll be 
because there is a problem with speed, and you'll track it down by using 
the available benchmarking and profiling tools.

There isn't a 'wrong' way to do what you want to do. There are benefits 
and drawbacks as much as there are specific reasons you'd use each.

Personally, I use shift for the most part (as I design almost all of my 
interfaces with the args passed in as a single hash ref. In cases I 
don't use that type of API, it is because the sub only takes one or two 
args, in which a couple of shift lines isn't much extra typing).

Steve


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About