Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Prototypes allow overloading subs?

by Elian (Parson)
on Dec 04, 2002 at 21:54 UTC ( #217608=note: print w/replies, xml ) Need Help??


in reply to Re: Prototypes allow overloading subs?
in thread Prototypes allow overloading subs?

It would be helpful if you could give an example of an application or a pattern where such a technique of distinct routines to handle different arglists would be useful.
Here's an easy one off the top of my head:operator overloading. Not often done, but useful. You would, for example, want to handle multiplication differently if the left and right sides of the * were both matrices then you would if the left side was a matrix and the right a scalar. (In the first example you'd probably do a full matrix multiply, and in the second you'd probably multiply each element of the matrix by the scalar. Probably...)

Any time you have a sub that checks the passed parameters and then dispatches to different code depending on the type or quantity of the parameters you're a good candidate for this. It's much less error prone (and usually faster) if the language handles the dispatch.

  • Comment on Re: Re: Prototypes allow overloading subs?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-01-19 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?