Funny. There a number of situations where ive taken advantage of this very feature. And frankly would have been annoyed if the code warned when I did so. An example might be a situation where we extract the contents of a line via a regex, and then process that line via a dispatch function:
or something like it. Another example would be overriding a method in a class that takes a certain number of parameters with one that takes a few more. When calling the overriden sub its fairly natural say something likemy ($meth,@parts)=/.../; exists($dispatch{$meth}) and $disptach{$meth}->(@parts);
So IMO warning when someone passes too many parameters seems a little extreme. If you do that then I at least hope that yousub blah { $foo->SUPER::blah(@_); ... }
so that I can turn off the annoying messages instead of having to write tortured code just so your sub gets the correct number of parameters. I have come across a similar annoyance when people use prototypes (usually for the wrong reasons, such as argument count checking).use warnings::register;
I'm especially paranoid against other programmers,
Im sympathetic to this postion, but I think its a fine line between being paranoid, and being unduely restrictive. If the end user wants to give you more arguments then you need, then theres a decent chance that decision was a sound one. At a certain point you have to let the end user take responsibility for their own code, and thus their own (mis)use of your code. I certainly disagree with code that makes it impossible to do something just because the author couldnt see any reason why anyone would want to do it. (A position that you arent necessarily advocating I realize, but you can see the relevance I hope.) A good example is code like this:
Cheers,sub foo { my $array_ref=shift; ref($array_ref) ne "ARRAY" and die "Can't use anything but an array"; ... }
--- demerphq
my friends call me, usually because I'm late....
In reply to Re: Re: Context aware functions - best practices?
by demerphq
in thread Context aware functions - best practices?
by Aristotle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |