Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Are prototypes evil?

by lestrrat (Deacon)
on Sep 03, 2002 at 10:05 UTC ( #194715=note: print w/replies, xml ) Need Help??

in reply to Are prototypes evil?

I think when they are called for ( such as when you described "... I like the ability to use subs like built-ins.." ), they can be good. The reason most people that I know detest them is because it gives you false sense of security

For example, you may think that a sub foo($) would force perl to raise an error if you passed an array to it. But this produces no errors:

my @list = qw/ foo bar baz /; foo( @list );

instead, you get size of the list.

I find this to be extremely dangerous, because a lot of people expect "prototypes" to work sort of like C/C++/Java prototypes, and what's worse, it sometimes seems to work that way as well (For example, foo($a,$b) would in fact generate an error)

That's exactly why I don't like them, and almost never use them except for in esoteric cases. At the very least, I think the use should NOT be encouraged.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194715]
choroba sees 5
Discipulus more.. and count cloaked monks..
shmem joins the club
[Discipulus]: welcome back to Tkperlmonks virtualsue! ;=)
[virtualsue]: I missed my 17 year anniversary
[erix]: a virtualanniversary , seems apt enough :P
[marto]: :(
[Discipulus]: we can remedy: ♪♫ Happy monkday to you, Hapymonkday virtualsue..♫..
hippo waves at the other 6

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2018-04-24 11:03 GMT
Find Nodes?
    Voting Booth?