polymorpheus has asked for the wisdom of the Perl Monks concerning the following question:
I came up with what I think is another valid reason for using function prototypes even though I generally agree they should not be used.
And, of all places, I am suggesting using them on methods. Yes methods, where prototypes are known not to work.
So why you ask?
To prevent people from calling your methods as functions.
For example, the docs for UNIVERSAL::isa say not to call it as a function. But people do it all the time. if they had declared it like this:
then they could have prevented this widespread misuse of the API.sub isa() { ... }
Has anyone seen this mentioned anywhere else? I don't think PBP or Modern Perl mention this.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Good use for prototypes. On methods no less!
by chromatic (Archbishop) on Jun 01, 2012 at 20:00 UTC | |
Re: Good use for prototypes. On methods no less!
by Eliya (Vicar) on Jun 01, 2012 at 19:45 UTC | |
by polymorpheus (Novice) on Jun 01, 2012 at 19:55 UTC | |
by Eliya (Vicar) on Jun 01, 2012 at 20:04 UTC | |
Re: Good use for prototypes. On methods no less!
by thargas (Deacon) on Jun 04, 2012 at 11:26 UTC | |
by polymorpheus (Novice) on Jun 04, 2012 at 16:41 UTC | |
by thargas (Deacon) on Jun 05, 2012 at 12:09 UTC | |
by polymorpheus (Novice) on Jun 05, 2012 at 13:04 UTC |