[Edinburgh-pm] Parameter passing, seeking an answer....

Rory Macdonald rory.macdonald at gmail.com
Thu Sep 6 01:26:47 PDT 2007


On 9/6/07, Ian Stuart <Ian.Stuart at ed.ac.uk> wrote:
> When I first started coding, I'd pick up parameters in functions thus:
>
> sub myFunc {
>   my self = shift;
>   # stuff
> }
>
> I've noticed that people have moved to a new style:
>
> sub myFunc {
>    my ($self) = @_;
>    # stuff
> }
>
> Is there a good compelling reason for this (new to me) style?

Without context? No.  But there's nothing new about it. Depends on
what you've been reading I guess.

If you had to scratch for reasons to do "my ($self) = @_;" then;

* its less code to change if you add to the parameter list
* its fewer instructions/lines if you add more params than a series of
shifts (although it may well be optimized down to the same thing as
the "() = @_" behind the scenes?)
* in a code base where various functions accept varying numbers of
params, then consistency in this area may help maintenance (think
coding standards)

Rory


More information about the Edinburgh-pm mailing list