Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: When to use Prototypes?

by Rex(Wrecks) (Curate)
on Nov 10, 2001 at 00:56 UTC ( #124477=note: print w/ replies, xml ) Need Help??


in reply to When to use Prototypes?

I think I'm about to lose my newly earned 'monk' status with this post, but here goes anyway.

I use prototypes for any sub I write that does not take a scalar(s) as args. I do this for 2 reasons:

  • First, it helps for readability of larger scripts, and just by looking at my sub prototypes at the top I know what to pass it.
  • Second, for maintainability, when I look at stuff I wrote months ago I can see exactly what I'm passing and how to reuse that sub easily.
    Now this could also be because I write too much C, and like to see what is being passed around at a glance, personally, prototyping helps. Being able to pass an array ref (like you have to) in the same way I would (logically) pass an array (like I would want to) is also more readable for me.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!


  • Comment on Re: When to use Prototypes?
    Download Code
    Replies are listed 'Best First'.
    Re^2: When to use Prototypes?
    by Aristotle (Chancellor) on Nov 10, 2001 at 21:18 UTC
      I don't think it does much for readability, since at best you see the projected type of argument, but still have to look the meaning of each of them. Putting a cleanly written and commented local variable assignment like my ($ip, $port, $use_udp, $msg_array) = @_; at the top of a function will probably help a lot more.

    Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (18)
    As of 2015-07-31 15:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (279 votes), past polls