Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Looking at the post in question, I'll guess that John is using prototypes to validate the number of arguments passed into each sub at compile time. I can certainly understand the desire to do that. I've even done that in the past. But I found that the misfeatures of Perl 5 prototypes outweighed this desirable effect (see the reference article for the full story on those misfeatures).

Now I only use prototypes for making compile-time constants and to emulate map's and grep's ability to take bare blocks as code references (and this latter use is quite rare and really only gives a very minor benefit of not having to see "sub" in front of each block).

Making compile-time constants is really the only use of prototypes that I can recommend.

BTW, I check the arguments passed into subroutines rather thoroughly, inside the subroutine, at run time. And I prefer to have test suites that validate the code paths so that this validation is effective before going into production, even though the checking isn't done at compile time. Since Perl uses a lot of late binding, checking subroutine arguments at compile time often just isn't possible.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: When to use Prototypes? by tye
in thread When to use Prototypes? by demerphq

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found