Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re (tilly) 1: When to use Prototypes?

by tilly (Archbishop)
on Nov 09, 2001 at 17:19 UTC ( #124349=note: print w/ replies, xml ) Need Help??


in reply to When to use Prototypes?

As you well know, my answer to when to use prototypes is generally, Don't!

And an example that I would point to of what the bugs caused by prototypes working as designed (rather than by their being buggy) look like in practice, take a look at printf vs. sprintf. How quickly could you, or more importantly a co-worker of yours, figure out what went wrong there? Why would you want to subject yourself to going wrong like that when you have a choice?

On whether prototypes are a bad idea, I don't think they are in a language where they do something reasonable. But they don't in Perl.


Comment on Re (tilly) 1: When to use Prototypes?
Re: Re (tilly) 1: When to use Prototypes?
by Masem (Monsignor) on Nov 09, 2001 at 19:13 UTC
    ...or at least in Perl 5.

    As pointed out in Apocolypse 2 (where's the danged thing on perl.com??) or Exegensis 2, perl 6 will have much better prototyping featurs, such that you can have something like:

    # PERL 6!!!! @array1 = ( 1..5 ); @array2 = ( 6..10 ); do_array_magic( @array1, @array2 ); #... #... sub do_array_magic ( ARRAY $a, ARRAY $b ) { # @a is [ 1,2,3,4,5] # @b is [ 6,7,8,9,10 ] }
    instead of
    # PERL 5 @array1 = ( 1..5 ); @array2 = ( 6..10 ); do_array_magic( @array1, @array2 ); #... #... sub do_array_magic { (@a, @b) = @_; # @a is [1..10] # @b is empty. }

    But prototyping in p5 is mearly a pain, and even if you do check the args by prototype, you still probably need a block of warn or die statements as you check arguments for validity at the start of the sub. So they mearly get in the way instead of being useful currently.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://124349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2015-07-04 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls