I see advantages and disadvantages in each alternative, leaving me quite ambivalent. They are close enough that I think it would be difficult to make a seriously bad decision between them.

Which implementation is clearer will depend on what the reader/developer is familiar with. I would have thought the "literal" code would be more easily understood but your initial reaction proves the point that what is clear is quite personal.

The currying function uses a closure which, conceptually, isn't trivial. Otherwise, there is little difference in the set of language features used. On this basis, I would say the currying function is a little less "clear". But, for those familiar with closures, I guess it is at least as clear.

The currying function allows the function and default arguments to be set with minimal clutter at the expense of "hiding" what is being done with the arguments in a "remote" block of code. Not much of a problem when that block is adjacent to the function call as in the example, but at least a slight impediment to easy understanding if they are at a greater distance.

I agree the currying function is more DRY. Also, if there are many functions being set, it makes it much clearer that they are all being handled in the same way. This clarity should improve scalability. This and the reduction of typing should improve maintainability. The significance of this advantage increases as the scale of the project (number of functions being set) increases.

Yet, there is also clarity and ease of maintenance in the terseness and immediacy of ikegami's implementation, particularly for smaller (fewer functions) projects.


In reply to Re^5: Subroutine references inside of a hash with arguments. by ig
in thread Subroutine references inside of a hash with arguments. by shift9999

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.