Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: My coding guidelines

by jryan (Vicar)
on Nov 25, 2002 at 19:18 UTC ( #215706=note: print w/ replies, xml ) Need Help??


in reply to Re: My coding guidelines
in thread My coding guidelines

You are missing something, here are two examples:

# prototypes only check arg format # i.e. (scalar/array/hash/code/glob and number of args) package Sample; sub stringify () { return ($_[0]->{data}) x $_[1] } package main; sub print_string($) { print $_[0]->stringify(1) } my $obj = bless ( {data=>"foo\n"}, 'Sample'); print_string($obj); # fine print_string(5); # uh oh... basic numbers don't have a stringify me +thod, # yet the arg passed the prototype since 5 is a sc +alar.
And also:
# methods don't check prototypes... at all. sub print_string_bad($) { print $_[0]->stringify() # Will pass the prototype, yet break since $_ +[1] will be # undef in stringify } print_string_bad($obj);

Hence the reason for the general distaste for prototypes among the perl community. For most cases, they're pointless. They're only there so that you can call your own subs like perl-builtins.


Comment on Re: Re: My coding guidelines
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://215706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-09-18 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls