in reply to Re^2: This "each" goes to endless loop each time...
in thread This "each" goes to endless loop each time...
The full quote is "It's probably best to prototype new functions, not retrofit prototyping into older ones" with the strong implication that it only applies in the context of adding prototypes to old subs. It is followed by a brief explanation of why retrofitting should be avoided: "That's because you must be especially careful about silent impositions of differing list versus scalar contexts". And that is the crux of the problem - prototyped subs don't do what you expect in some situations and often lead to very hard to see and debug problems. It is unfortunate that so much space in the documentation is given to a feature that should have a large "Here be dragons" label on it.
Note too that "the intent of this feature is primarily to let you define subroutines that work like built-in functions" could (and according to informed opinion: should) be read to mean the only time prototypes should be used is to emulate built in functions.
Note too the final comment in the prototype section of the documentation: "This is all very powerful, of course, and should be used only in moderation to make the world a better place.".
Much has been written about prototype at PerlMonks. Some of the following may be interesting: subroutine prototypes still bad?, The purpose of prototypes in perl subroutines, Considering Prototypes, Are prototypes evil? and many others.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: This "each" goes to endless loop each time...
by rovf (Priest) on Jun 20, 2008 at 07:50 UTC |