I recently posted a question in which it was kindly mentioned that my use of prototypes was probably inappropriate. I went ahead and did some reading on it, and I'm still a bit curious and have a few questions.

First, why *doesn't* Perl support strict function-argument specification? I can see that prototypes don't really do this, but... I'm surprised that there is no easy way to enforce it. Is this a result of the way Perl seamlessly casts between ints and strings?

Second, many of the prototype-problems seem to come down to the functions accepting "weirdness" despite the prototype. But from the article it did appear that passing reference to data-structures (e.g. sub foo(\%) {}) wasn't too problematic: mainly coming down to issues of "semantic sugar" rather than unexpected behaviour. Is that a misconception?

It still seems "clearer" to my eyes to see the data-types expected of a function specified in its declaration. I'm trying to "adjust" my eye-sight by just taking it out and putting it in comments at the start of the routine, but I figured I should try to understand why I'm doing it this way as best as possible!


In reply to Considering Prototypes 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.