I myself am doing the same exact thing as you, basically making my subroutines "generic", (at least any subroutine I write that could ever be used again) more for my own code library and the benefit of the practice than a module or anything, but I haven't really taken the approach of using prototypes. At the mention of making my subroutines generic, my guru suggested using them, but upon my own research, I just didn't see the benefit, seems a bit redundant to me, perhaps I'm missing their functionality/purpose?
If there's any correlation between prototypes and genericness, it's a negative one. I'd say that prototypes make functions
less generic.
In general, I don't use prototypes, unless they give me a benefit at compile time. Prototypes I may consider using:
- The empty prototype, for making constants.
- The single scalar prototype, ($), as it allows for making unary name functions, which are parsed differently: foo bar $baz, $quux; depending on the prototype of bar, $quux is a parameter for foo or bar. Note that I mean a prototype consisting of only a $, and nothing else.
- The give me $_ prototype, _. Have never used it so far.
- The coderef prototype, &, so I can pass in a coderef as a bareblock, instead of having to use the sub keyword. I don't think I've ever used & in a prototype other than (&@).
In all other cases, prototypes are much more of a hassle than they are worth it. And often, they are just plain annoying.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.