On 9/16/05, Steve Dawson <[EMAIL PROTECTED]> wrote:
> > BTW, for recursion to work with prototypes you need to pre-declare the
> > subrouting. For example:
> > sub test_sub ($$);
> >
> > sub test_sub ($$) {
> > my $str = shift;
> > my $num = shift;
I prefer
sub test_sub($$){
my($str,$num) = @_;
...
because I often optimize the my-vars out and refer directly into @_
in short subroutines, and writing it that way gives me an easier
optimization path. It's as close as perl5 gets, IMO, to named arguments.
I like prototypes because they enforce the defined interface: when a function
is supposed to take some number of arguments, they must all be there or
there is a compile-time error.
I think the current behavior of requiring predeclaration of prototypes
for recursive
use is broken, but using the workarounds is clearly easier than doing the work
required to fix the problem, so I doubt it will be repaired. &
calling will bypass
the prototype check, so adding an ampersand could be considered an easier
workaround than adding a declaration, but OTOH the recursive call will
be examined
many more times than it is written, as you try to remember what
exactly the function
does, when you are maintaining it, so it is good to have the recursive
call in the
recursive function follow the same protocol as is reccommended for use of the
recursive function outside of itself.
Back to work
David Nicol
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs