On 2012-05-21 14:51, Shawn H Corey wrote:
On 12-05-21 04:32 PM, Steve Bertrand wrote:
On 2012-05-21 14:12, sono...@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).
Also, you don't not know when the internals of perl will change and make
the other method slightly faster. It is better to write things so you
will understand them in the future then to optimize without need.
That's a very good point.
Steve
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/