in reply to Gratuitous use of Perl Prototypes
I completely agree with the {sentiment embodied in} the title of your meditation.
However, I think that the word "gratuitous" is important. If prototypes were truely evil, as opposed to just widely misunderstood (Poor things. All say "Ahhh!"), then I think they would have been officially deprecated long ago.
But they haven't. Maybe, because they do allow some things to be done that cannot be done any other way. And whilst you may question the necessity of doing those things, the desirability of them, when they are justified, is enough to keep them included in the langauge.
Example: Remove the prototype from this implementation of zip and then modify the code to compensate and you get a much less readable and useable function.
#! perl -slw use strict; local $, = ' | '; sub zip (&\@\@) { map { $_[ 0 ]->( $_[ 1 ][ $_ ], $_[ 2 ][ $_ ] ) } 0 .. ( @{$_[ 1 ]} < @{$_[ 2 ]} ? $#{ $_[ 1 ] } : $#{ $_[ 2 ] } ); } my @a = 'a' .. 'z'; my @n = 1 .. 10; print zip{ "@_" } @a, @n; print zip{ $_[ 0 ] .= $_[ 1 ] } @a, @n; print zip{ $_[ 0 ] .= $_[ 1 ] } @a, @n; __END__ [ 1:37:32.71] P:\test>406231 a 1 | b 2 | c 3 | d 4 | e 5 | f 6 | g 7 | h 8 | i 9 | j 10 a1 | b2 | c3 | d4 | e5 | f6 | g7 | h8 | i9 | j10 a11 | b22 | c33 | d44 | e55 | f66 | g77 | h88 | i99 | j1010
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Gratuitous use of Perl Prototypes
by dragonchild (Archbishop) on Nov 09, 2004 at 14:25 UTC | |
by BrowserUk (Patriarch) on Nov 09, 2004 at 15:42 UTC | |
by dragonchild (Archbishop) on Nov 09, 2004 at 16:08 UTC | |
by BrowserUk (Patriarch) on Nov 09, 2004 at 17:32 UTC |