in reply to Re^3: perl and apache2 on ubuntu 17.04
in thread perl and apache2 on ubuntu 17.04
there is giant reason i use prototypes. but, i would like to know WHY it's such a giant deal that i do.
Please see Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen. Just to briefly name a few issues, Prototypes do much more than just check how many arguments are passed to a function, they also affect how Perl code is parsed and how arguments are passed to functions (e.g. arrays are magically turned into arrayrefs where normally they would get flattened). If you have "lots of subs in many different modules", can you recall what the prototype of each and every one is? How about someone else using your code, or a future maintainer, will they be surprised at how their code gets parsed? Plus, just call a sub as &foo(...) and the prototype is ignored, and they're also not used for method calls.
Note I'm not saying you shouldn't ever use them. But they're not really meant as a "check the number of arguments passed to a sub" feature, for that you've got @_==3 or croak "bad number of args to X", modules like Params::Validate, or even the experimental Signatures. Prototypes are best for functions that extend the Perl syntax (e.g. the way Try::Tiny does it), and if you do use them, you should be aware of all of the issues.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: perl and apache2 on ubuntu 17.04
by jamroll (Beadle) on Jul 19, 2017 at 13:57 UTC | |
by choroba (Cardinal) on Jul 19, 2017 at 19:36 UTC | |
by jamroll (Beadle) on Oct 13, 2018 at 19:35 UTC | |
by haukex (Archbishop) on Jul 23, 2017 at 21:08 UTC |