Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Good use for prototypes. On methods no less!

by thargas (Deacon)
on Jun 04, 2012 at 11:26 UTC ( #974270=note: print w/ replies, xml ) Need Help??


in reply to Good use for prototypes. On methods no less!

Hmmm. I can certainly understand why PBP wouldn't refer to this as I can't imagine anyone would claim that this is a best practice.

Why are you wanting to do this? Are you really having that many people who can't read the docs? Personally, if someone has ignored the docs sufficiently to be calling a method as a function, I don't really care what happens to their code; it's unlikely to do anything useful and they'll notice that, unless they don't care, in which case ...


Comment on Re: Good use for prototypes. On methods no less!
Re^2: Good use for prototypes. On methods no less!
by polymorpheus (Novice) on Jun 04, 2012 at 16:41 UTC

    I don't necessarily want or need to do this, but yes, I was considering this in the context of best practices.

    As you note, and Chromatic points out, the malicious user can easily get around this defense, but what about the novice user? it might help prevent a few bad cases from creeping into the code base. I have also been considering recommending an empty prototype on functions that do not take any args as this appears to be the one case where they are useful at pointing out usage errors early (compile time) to the user.

    At a minimum, I am wondering about a perl critic exception to allow smart use of prototypes.

      OK. If you're considering this in the context of novice users, I would say, please don't do this. The error you get is going to be misleading:

      Too many arguments for Thing::hack at ./proto-method line 16, near "1) +" Execution of ./proto-method aborted due to compilation errors.

      If your goal is to help novice users, this seems to me not to be the a good idea, as the error says nothing about the actual problem. I don't think that this idea will help anyone, except in the sense that calling the method as a function will fail, unless they pass it no args.

      Sorry. I've got no alternative suggestion, but I don't like this idea.

        Good point about novices. If the error message actually said "method called as a function" then it might be nice.

        I think I will give up on this one. Thanks for all the feedback!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-12-29 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls