in reply to subroutine prototypes still bad?
The problem with prototypes is not that they are poor form, it's that they don't do what most people expect from their experience with Java or C. They are usually unnecessary in Perl, and if misused are the source of confusing bugs. Bugs particularly confusing to the person who wrote them.
Perl prototypes override normal parsing of a sub's arguments. They can be used to prevent the flattening of arrays, for instance. Normally, in foo(@bar,@baz), the two arrays will be merged into a list of both their contents in order. If foo were given the prototype '\@@', however, @bar is treated as a unit, joining the argument list as a reference to itself. The foo() function will treat its arguments the way that push does.
The empty prototype is a particularly interesting one. It causes Perl to try to unfold sub parsing and produce a constant at compile time. It can have profound effects on how a statement is parsed.
I'm not clear on what you mean by your reference to strict and warnings. As far as I know, those are unrelated to prototypes, other than a few warnings which indicate that a prototype will not be honored or a sub call has ambiguous syntax.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: subroutine prototypes still bad?
by doom (Deacon) on Jun 13, 2007 at 17:11 UTC | |
|
Re^2: subroutine prototypes still bad?
by Anonymous Monk on Jun 13, 2007 at 00:26 UTC | |
by Zaxo (Archbishop) on Jun 13, 2007 at 00:28 UTC | |
by Anonymous Monk on Jun 13, 2007 at 00:36 UTC | |
by Joost (Canon) on Jun 13, 2007 at 02:04 UTC |