Dan Anderson wrote:
>
> I am somewhat confused as to when to prototype a subroutine.  Under the
> tips section Programming Perl makes the following points:
>
> 1.  Prototyping can lead to inlined functions which increases the speed
> of commonly used functions.  Prototype when you can.
>
> 2.  As soon as somebody uses your function in a way it wasn't supposed
> to be used, your program can explode.  Never prototype.
>
> (This is not verbatim -- but it's the same general idea)
>
> Can anyone go more in depth about the pros and cons of prototyping?

Everybody who has an opinion on this will have a different one, so
here's mine:

- Forget about optimising your program until you've found that it's
  too slow.

- Only ever prototype well-established functions that you want to
  write /very/ well (including optimisation and parameter
  verification) and then forget about them.

- As far as possible, code all calls to prototyped subroutines without
  brackets around the parameter list. Like this:

    noproto('A', 1);
    withproto 'A', 1;

  so that the difference is clear.

- A special case is prototyping the subroutine for a call to 'sort'
  which will allow you to pass the two parameters in the @_ parameter
  list instead of in package variables $a and $b.

Like I said, read what others have to say and adopt your own policy,
but be consistent.

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to