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
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|