title: In Python, partial function application (currying) versus explicit function definition
body: <p>In Python, is it considered better style to:</p>
  
  <ul>
  <li>explicitly define useful functions in terms of more general, possibly internal use, functions; or,</li>
  <li>use partial function application to explicitly describe function currying?</li>
  </ul>
  
  <p>I will explain my question by way of a contrived example.</p>
  
  <p>Suppose one writes a function, _sort_by_scoring, that takes two arguments: a scoring function and a list of items.  It returns a copy of the original list sorted by scores based on each item's position within the original list.  Two example scoring functions are also provided.</p>
  
  <pre><code>def _sort_by_score(scoring, items_list):
      unsorted_scored_list = [(scoring(len(items_list), item_position), item) for item_position, item in enumerate(items_list)]
      sorted_list = [item for score, item in sorted(unsorted_scored_list)]
      return sorted_list
  
  def _identity_scoring(items_list_size, item_position):
      return item_position
  
  def _reversed_scoring(items_list_size, item_position):
      return items_list_size - item_position
  </code></pre>
  
  <p>The function _sort_by_score is never called directly; instead, it is called by other single-argument functions that pass a scoring function and their lone argument (a list of items) to _sort_by_scoring and return the result.</p>
  
  <pre><code># Explicit function definition style
  def identity_ordering(items_list):
      return _sort_by_score(_identity_scoring, items_list)
  
  def reversed_ordering(items_list):
      return _sort_by_score(_reversed_scoring, items_list)
  </code></pre>
  
  <p>Obviously, this intent is better expressed in terms of function currying.</p>
  
  <pre><code># Curried function definition style
  import functools
  identity_ordering = functools.partial(_sort_by_score, _identity_scoring)
  reversed_ordering = functools.partial(_sort_by_score, _reversed_scoring)
  </code></pre>
  
  <p>Usage (in either case):</p>
  
  <pre><code>&gt;&gt;&gt; foo = [1, 2, 3, 4, 5]
  &gt;&gt;&gt; identity_ordering(foo)
  [1, 2, 3, 4, 5]
  &gt;&gt;&gt; reversed_ordering(foo)
  [5, 4, 3, 2, 1]
  </code></pre>
  
  <p>Apparent advantages of the explicit function definition style:</p>
  
  <ol>
  <li>useful functions may be defined before the more general functions are, without raising NameErrors;</li>
  <li>helper functions (e.g., scoring functions) could be defined within the function definition body;</li>
  <li>possibly easier to debug;</li>
  <li>code looks nice by virtue of "explicit is better than implicit."</li>
  </ol>
  
  <p>Apparent advantages of curried function definition style:</p>
  
  <ol>
  <li>expresses intent of functional programming idiomatically;</li>
  <li>code looks nice by virtue of succinctness.</li>
  </ol>
  
  <p>For defining "useful" functions, which of the two styles is preferred?  Are there other styles that are more idiomatic/Pythonic/etc.?</p>