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


In reply to Re: subroutine prototypes still bad? by Zaxo
in thread subroutine prototypes still bad? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.