Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > prototypes - use or not?

Reply
Thread Tools

prototypes - use or not?

 
 
Dan Becker
Guest
Posts: n/a
 
      03-27-2007
Perl Best Practices (Conway), section 9.10, has a pretty clear statement
that subroutine prototypes should not be used. Period. (It says that the
disadvantages generally outweigh the limited advantages.) But it's still in
the language. So I'm confused. Is this generally accepted advice? or should
it be applied only in specific situations? or, generally speaking, avoided
in specific situations?

Dan Becker


 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      03-27-2007
>>>>> "DB" == Dan Becker <(E-Mail Removed)> writes:

DB> Perl Best Practices (Conway), section 9.10, has a pretty clear
DB> statement that subroutine prototypes should not be
DB> used. Period. (It says that the disadvantages generally outweigh
DB> the limited advantages.) But it's still in the language. So I'm
DB> confused. Is this generally accepted advice? or should it be
DB> applied only in specific situations? or, generally speaking,
DB> avoided in specific situations?

just because PBP doesn't like something doesn't mean it will be removed
from perl5. about the only think i know that has ever been removed was
pseudo-hashes and they were very bad and evil. prototypes have a few
real uses but almost none for the average perl hacker. so the point is
just what pbp says, don't use them unless you have a very good reason to
use them. if you can't figure that out, then you don't know enough to
use them. among other dumb things newbies do is use prototypes on
methods where they have no effect at all.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      03-27-2007
Dan Becker wrote:
> Perl Best Practices (Conway), section 9.10, has a pretty clear statement
> that subroutine prototypes should not be used. Period. (It says that the
> disadvantages generally outweigh the limited advantages.) But it's still in
> the language. So I'm confused. Is this generally accepted advice? or should
> it be applied only in specific situations? or, generally speaking, avoided
> in specific situations?


See also Tom Christiansen's article "Far More Than Everything You've Ever
Wanted to Know about Prototypes in Perl" at:

http://library.n0i.net/programming/p...fm_prototypes/



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
 
Reply With Quote
 
Xiong Changnian
Guest
Posts: n/a
 
      03-31-2007
In article <46098403$(E-Mail Removed)>,
"Dan Becker" <(E-Mail Removed)> wrote:

> Perl Best Practices (Conway), section 9.10, has a pretty clear statement
> that subroutine prototypes should not be used. Period.


The trouble with prototypes, as I see it, is that they may not do what
you expect -- depending, of course, on what you expect. Prototypes don't
do type checking; rather, they force types. I think it might be better
to write your code so as to supply the right type of param in the first
place.

In most cases, I believe, if you're thinking about prototypes, you'd be
better off checking params explicitly and writing good docs.

Prototypes doubtless have their uses and if you stick with this thread
long enough, you'll find an avid supporter. I'm not going to get into a
war over them. I do suggest that before you decide to use them, you
spend quite a bit of time learning exactly what they do and do not do.
--
Xiong Changnian
xiong102ATxuefangDOTcom

--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
gf
Guest
Posts: n/a
 
      04-09-2007

Dan Becker wrote:
> Perl Best Practices (Conway), section 9.10, has a pretty clear statement
> that subroutine prototypes should not be used. Period. (It says that the
> disadvantages generally outweigh the limited advantages.) But it's still in
> the language. So I'm confused. Is this generally accepted advice? or should
> it be applied only in specific situations? or, generally speaking, avoided
> in specific situations?


Conway says it's usually not a good idea but gives examples when you
might want to. It's up to you to decide whether the prototypes make
sense or not in a particular script.

Personally, I don't use them. I write in checks when I enter a
subroutine to see if I've gotten sensible values and/or types for the
parameters.

I also stopped using positional parameters in subroutines and instead
follow Conway's recommendation to use hashes or hash-refs. Doing that
opens up some interesting possibilities for using defaults for values
not passed in, or passing in a set of defaults and overriding a
particular value. It makes for more typing as I write the code
initially, but I think my reuse goes up over time.

 
Reply With Quote
 
Michael Carman
Guest
Posts: n/a
 
      04-10-2007
On 4/9/2007 4:08 PM, gf wrote:
>
> I also stopped using positional parameters in subroutines and instead follow
> Conway's recommendation to use hashes or hash-refs. [...] It makes for more
> typing as I write the code initially, but I think my reuse goes up over time.


It also makes it a lot easier to read/debug when you can tell what's what from
the call. That said I find that functions with <= 3 parameters are usually
clearer with positional notation.

-mjc
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scope/use of prototypes Qs pemo C Programming 9 03-31-2006 10:11 PM
How To Build Parallel Port Prototypes Silverstrand Front Page News 1 10-14-2005 05:33 AM
Toshiba Prototypes 30 GB HD DVD Disc. (Recordable) Allan DVD Video 1 07-20-2005 07:29 PM
Prototypes of html-pages Lars Hedström HTML 3 04-08-2004 07:48 PM
Prototypes for functions with default arguments Paul Davis C++ 2 07-15-2003 07:07 AM



Advertisments