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

Re: Are prototypes evil?

by Aristotle (Chancellor)
on Sep 02, 2002 at 22:19 UTC ( #194645=note: print w/replies, xml ) Need Help??


in reply to Are prototypes evil?

Prototypes are one of those things that you shouldn't use, unless you understand why you shouldn't use them. Consider
sub foo ($$) { print join " / ", map "'$_'", @_; } my @x = qw(a b); foo(@x);
This will print '2'. Not 'a' / 'b' as one might expect. Prototypes in Perl aren't. They would probably best be called "context coercion templates". A $ will coerce anything into a scalar. List/hash flattening no longer applies. When using a single ($), it's not too bad, but if you use prototypes for more parameters, you can easily surprise users of that function (including yourself). The only "prototype" I'd seriously consider is &, which lets me pass a bare(!) BLOCK that implicitly becomes a subref to a closure to the function.

Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194645]
help
Chatterbox?
Discipulus s/silbing/whistle/ dunno from where this word was in my mind..
[Discipulus]: lost in time in space and in the meaning (rocky horror picture show)
[Corion]: Discipulus: Yeah, a short vacation on the Canary islands (Lanzarote). Always great to be in the warmth and sun, from a cold and rainy February here ;)
[Corion]: choroba: Yeah, you have to find a time for the regular skype (or whatever) meetup, I imagine that's hard
[choroba]: Lanzarote is great!
choroba went there year ago

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2017-02-22 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.