in reply to Re: how does splice do it?
in thread how does splice do it?
Do be careful with using prototypes vs. passing references. IMHO, code is much more readable and maintainable if you make a habit of passing references. In this manner, you don't have to look at the subroutine declaration to see what arguments it expects.
It seems to me that some core perl functions, such as splice, push, pop, shift and unshift use prototypes because the name of the functions as well as the way they are called read easier in the english language. "Push onto this array the following list" rolls off the tongue better than "Call the push() function with a reference and a list to add to it". push \@array, @list; just doesn't look right. Whenever I see a call to a subroutine with an array as the first argument, I generally assume that a copy of an array is being passed to the subroutine and that each item in the array will fill @_, not that it will all be within $_[0].
It all comes down to a matter of preference, but I'd like to think that more people stick to passing references than creating a prototype for every subroutine they write. I'd be interested in hearing other opinions on this matter. Which method of passing arguments do you use more frequently and why?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re ^2: how does splice do it?
by John M. Dlugosz (Monsignor) on Jan 10, 2003 at 15:58 UTC | |
by paulbort (Hermit) on Jan 10, 2003 at 19:21 UTC | |
by John M. Dlugosz (Monsignor) on Jan 11, 2003 at 04:44 UTC |