If you wish, regard this as just an element of
TWikiCodeStyle. However, there are very
good reasons
for this. Feel free to read the discussion below for some background as to how this question came up.
--
WalterMundt - 19 Jan 2003
I've been hacking on the TWiki rendering code locally, and have noticed that you guys don't seem to be using Perl function prototypes. I tend to prototype my functions when I write them, and so would like to know whether this is a policy thing. IE, if I submit a patch with some new functions that use prototypes, would you guys feel the need to modify it so that they werent? Note that in some cases this is non-trivial, since "\%" type prototypes actually change the calling syntax for the function.
--
WalterMundt - 16 Jan 2003
I don't think that Perl prototypes are particularly useful, since they don't actually check the calling parameters - while they are justified in a few cases, such as your example, I'd prefer to avoid them except where really necessary to change the calling syntax in some way. Other developers may of course like prototypes
--
RichardDonkin - 16 Jan 2003
I recall some discussion ot
http://www.perlmonks.com
(which unfortunately I have no time to visit anymore) and common agreement was NOT use prototypes. Perl 6 I heard has better prototypes, worth using, but not now.
Just my .02, and I might be wrong - I do not want to promote "Cargo Cult Programming" (as defined by perlmonks).
--
PeterMasiar - 16 Jan 2003
The reference you want is
http://www.perl.com/pub/a/language/misc/fmproto.html
Prototypes in Perl
by Tom Christiansen
July 25, 1999
Far More Than Everything You've Ever Wanted to Know about
Prototypes in Perl
(Originally written for the perl5-porters mailing list.)
The article basically says "Don't waste your time, they don't buy you anything".
They seem to be a hangover from people coming to Perl from other langugages and carrying the gunnysack of expectation that those other languages taught them.
Rather like the rules in Latin such as "never end a sentence with a preposition" which simply do not apply to English.
"That is the sort of pedantic nonsense up with which I will not put." - Winston Churchill [ TomKagan 16 Jan 2003 ]
I quote:
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.
--
AntonAylward 16 Jan 2003
Well, that was informative. Thanks for linking me to that. I still find reference prototypes useful for debugging, solely because the very pedantic nature the author of the article complains about makes me ensure that I'm passing the right argument type, at least in that slot.
But if all the other coders on this are in agreement not to use them, I'll go ahead and remove them from any further code I submit. (They're already sprinkled throughout my
WikiTablesNeedRowspanning patch at the moment.)
--
WalterMundt - 16 Jan 2003
While I appreciate that Perl has evolved, I've been coding large (as in > 100,000 lines) systems in it since before Perl4 - that I remember (what I remember is the trauma of converting to Perl4!) I've also worked with stronly typed languages such as Algol, CORAl and ADA.
The issue isn't just that perl is an interpreter. So is APL; so it FORTH. The issue is "late binding". In this, Perl is more like (Bourne/Korn/Bash) Shell. In C/C++ the parameters are on the stck - proabbly the call-return stack - and their size (in bytes) matters. In Perl they are "pointers to internal descriptors" so it doesn't matter what the type is. (Not only is it not call-by-value in the sence of C/C++, its not like FORTRAN's call-by-address nor ALGOL's call-by-name.)
Since the sematics of the parameter is interpretive, it cannot serve the same "debugging" purpose as it would in C/C++.
If you think of Perl as sort-of C/C++ with some interpreter from Shell/Sed/Awk thrown in you're going to be limiting yourself.
If debuging is your concern, I'd strong recommend Martin Brown's book: ISBN0-07-212676-0 or at Amazon:
http://www.amazon.com/exec/obidos/tg/detail/-/B00007FYDR/104-8012615-5922333
His section on debugging
CGI applications is great.
I can't personally recommend his other books as I don't have them.
--
AntonAylward 16 Jan 2003
I know its not good form to comment on one's own comments, but ...
I've just been hitting the manuals and see that 5.6.x and later (one of our machines is running 5.8 - boy did that upgrade cause some odd problems with the security software!) and see that there are many
pragmas that are probably more use for enforcing good programming style and tracking problems.
The downside is that if you start modifying an existing piece of code and then use a pragma to help debug, you may find that the pragma uncovers many other pre-existing problems and marginal situations.
Personally I'd find that a good thing. I'm all in favour of making code robust.
--
AntonAylward 17 Jan 2003
Hopefully the above can be summarised as
please don't use Perl prototypes in TWiki code - they aren't very useful.
--
RichardDonkin - 19 Jan 2003
Or, looking into the future

: wait with Perl function prototypes until Perl 6 - they are not much usefull in Perl 5.
--
PeterMasiar - 20 Jan 2003