The soon to be indispensable "Perl Best Practices" (D. Conway,
O'Reilly.com -
http://www.oreilly.com/catalog/perlbp/
) puts it quite simply in Chapter 9 (coincidently on-line!) "Don't use
subroutine prototypes."
While the discussion goes on for a page and, to a point, could be saying
"don't use protos to handle trickier things like passing a scalar and an
array or ...", he says they're not going to really make code more readable
or robust and will leave you open for a false sense of security (for
instance an empty list is a valid list, as far as Perl is concerned) -
even worse, when used in OOP (where the subs are "methods") the protos get
ignored by design. Protos just don't solve a problem, due to Perl's
'interesting' skills in coercing one data type into another depending upon
context. Prototypes really specify which context a param will be
evaluated in, so passing an array as the first param to a sub that's got a
scalar as the first proto param def, will evaluate that array in scalar
context, using not the array but the element count of the array. Not what
you probably wanted and certainly not what anybody who's using your sub
will expect.
Likewise, he's got some negative things about using '&' ("the ancient Perl
4 syntax") to mark general subroutine calls. They don't help
'disambiguate' much as bare words are (should be) pretty much disallowed.
Depending upon how fancy you get w/ '&' as "logical and", using '&' can
do the wrong thing (his examples:
$cur_pos = tell &get_mas(); # means: tell(get_mask())
$cur_time = time &getmask(); # means: time() & get_mask()
) and the little known fact that:
&fix;
is actually
fix(@_);
YMMV but Dr. Conway's 'guidelines' are certainly worth considering. I'm
still trying to make my self use "/... /xms" every time I match and
un-cuddle my "els(?:e|if)" 's ;->
a
Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738 FAX 264-5932
nugatory 1. Trifling, negligible; of no intrinsic value or importance;
worthless.
1603 P. HOLLAND tr. Plutarch Morals 1156 That we may not range too farre,
nor use any superfluous and nugatory words.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs