I'm currently debugging a subroutine that takes exactly 61 arguments. After spending a few days working out how it's called ... Is it dreadfully expensive, in terms of memory usage?

A subroutine with 61 arguments is dreadfully expensive in terms of people time! Just think of the testing. The combination of tests cases you need to even partially cover such a beast is outrageous. And if everyone who needs to use the thing has to spend several days puzzling out the API, that's a huge hit.

Don't look at this as an excuse to pass a hash, look at it as an opportunity to refactor the subroutine.

The only time I've seen something with anywhere near that many parameters was in old (non-OO) FORTRAN code. I'll bet that many of those 61 parameters represent aspects of objects. Discover and create the right objects, and a good percentage of those parameters go away. And you can unit test the objects individually. Verifying that the internal states of several objects are consistent is much easier than flattening out and combining their internal representations, and then verifying that the resulting pile of values is in a consistent state.

Chances are also good that your subroutine is trying to do too much, but without seeing code, that's hard to tell.


In reply to Re: passing subroutine args as a hash: why not? by dws
in thread passing subroutine args as a hash: why not? by Willard B. Trophy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.