|No such thing as a small change|
When to use Prototypes?by demerphq (Chancellor)
|on Nov 09, 2001 at 16:23 UTC||Need Help??|
Recently I've had a few conversations regarding prototypes and when or if they should be used, then today I saw a post by John M. Dlugosz where he used them for as far as I could tell for no good reason. (Which should not be read that he had no reason, just that I couldn't figure it out. :-)
My thinking about protypes is that basically they are there to resolve unusal situations and should not be used except with extreme caution and very strong justification, but I have to admit that my thinking in this regard has been strongly influenced by Far More Than Everything You've Ever Wanted to Know about Prototypes in Perl by Tom Christiansen.
My feelings are pretty well summed up by two paragraphs from Christiansen's article
The major issue with ``prototypes'' in Perl is that the experienced programmer comes to Perl bearing a pre-conceived but nevertheless completely rational notion of what a ``prototype'' is and how it works, yet this notion has shockingly little in common with what they really do in Perl.
Which justifies my gut feeling that most time people use them they arent actually doing what the user thought and accoridingly are dangerous, both to the user and to the original programmer.
These mostly do nothing more that provide an implicit context coercion in order to spare the caller from having to sprinkle the code with calls to scalar() or to supply backslashes in order to pass aggregates by reference. They do comparatively little in the way of checking the type or number of arguments. So just what good are they, anyway?
Which even though I have read Christiansens article, and understand it as well, leads me to wonder why John used it and why and when the other monks use it, in fact Im curious to hear in general what the monastery thinks of prototypes and their use.
Yves / DeMerphq