develooper Front page | perl.perl5.porters | Postings from January 2011

RE: Time to update

Thread Previous | Thread Next
Jan Dubois
January 30, 2011 10:29
RE: Time to update
Message ID:
On Sun, 30 Jan 2011, Nicholas Clark wrote:
> I'm really not convinced that prototypes (as is) add any value in the general
> case. To my mind, they complicate reading the code, because they provide
> action-at-a-distance on how the parser is going to treat function calls.
> There seemed to be a fashion for using them extensively around 5.003-5.004
> time (for example, a lot of the regen code in the core), and looking at that
> code now, it feels dated to me, and lacking some KISS.

I always thought prototypes are primarily for the definition of CORE::GLOBAL::*
functions and similar.  This thought is somewhat supported by perlsub.pod:

       Because the intent of this feature is primarily to let you define
       subroutines that work like built-in functions, here are prototypes for
       some other functions that parse almost exactly like the corresponding

So I don't think prototypes should be used for "regular" functions that
don't try to implement some core-like primitives (e.g. using it for the
recently discussed kvmap() function seems sensible).

The only exception for non-core-like functions that I find sensible is using
the empty prototype for constant functions:

$ perl -wE 'sub FOO {3}; say FOO+1'
$ perl -wE 'sub FOO () {3}; say FOO+1'

Without the prototype the "FOO+1" is parsed as "FOO(+1)" instead of


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About