Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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

by Eliya (Vicar)
on Jun 01, 2012 at 19:45 UTC ( #973855=note: print w/replies, xml ) Need Help??

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

if they had declared it like this:

sub isa() { ... }

then they could have prevented this widespread misuse of the API.

How so (even if protoypes did work with methods)?

Wouldn't the effect rather be that you could now no longer call it as a method, nor with any parameter?

Replies are listed 'Best First'.
Re^2: Good use for prototypes. On methods no less!
by polymorpheus (Novice) on Jun 01, 2012 at 19:55 UTC

    Prototypes do nothing on method calls. There is plenty of talk about this in various forums. So they do not affect good users.

    If someone tries to call UNIVERSAL::isa(...) with arguments (what use would it be otherwise) they will get the compile time error.

    For example, this:

    > perl -e 'sub method() { }; main->method(1, 2, 3);'
    works, but this:
    > perl -e 'sub method() { }; main::method("main", 1, 2, 3);' Too many arguments for main::method at -e line 1, near "3)" Execution of -e aborted due to compilation errors.
    does not.

      Prototypes do nothing on method calls.

      Ah, sorry, I misread...   I thought you were suggesting that they should work with methods, too, and that this way all kind of problems (including the example presented) could be solved.  My bad!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973855]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-01-22 09:01 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.