Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Re^2: Function Prototypes and Array vs. List (Pt. 2)

by ariels (Curate)
on Jun 13, 2002 at 14:47 UTC ( #174225=note: print w/replies, xml ) Need Help??

in reply to Re^2: Function Prototypes and Array vs. List (Pt. 2)
in thread Function Prototypes and Array vs. List (Pt. 2)

No, your hypothetical create method is simply wrong. It's buggy. It should be (to paraphrase John Cleese) a NON-method. It should be bereft of life and pushing up the daisies.

The only reason to use prototypes is in order to give your functions the same syntax as various Perl builtins. E.g., with prototypes you can write a mymap that will have the same semantics as map. Your ``create'' method isn't doing that; it's using a prototype in order to create a bug.

I could equally well claim that map is broken, because this code

my %hash = map { $_ => X => 1 } qw(a b c d)
does something very strange.

You're right about coding, though: In order to make sure code does not have a bug, it is not enough to check documentation. You must look at the code.

Why are you using a prototype? So far you've shown excellent reasons for you not to use a prototype for this function. ``Doctor, whenever I leave the spoon in the cup and drink my tea, my eye hurts!''

Replies are listed 'Best First'.
Re: Function Prototypes and Array vs. List (Pt. 2)
by Abigail-II (Bishop) on Jun 13, 2002 at 16:13 UTC
    Eh, no, it's using a prototype to act as Perl buildins.... Remember that by default, subroutine calls gobble up all the arguments (unless there are parens), except subroutines that are prototypes to take zero or one argument. Witness:
    #!/usr/bin/perl -w use strict; sub all {print "@_\n"}; sub gobble_no_proto {return}; sub gobble_proto ($) {return}; all "foo", "bar", gobble_no_proto "baz", "quux", "fluff"; all "foo", "bar", gobble_proto "baz", "quux", "fluff"; __END__ foo bar foo bar quux fluff
    See the difference?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://174225]
[james28909]: in the rtp header, there is a nonce, i can just make this any number and increment it per packet?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-05-23 05:24 GMT
Find Nodes?
    Voting Booth?