[SciPy-dev] A quote of some relevance from Guido

Robert Kern rkern at ucsd.edu
Fri Oct 21 21:29:48 CDT 2005

Travis Oliphant wrote:
> I just picked up this little tidbit from python-dev.  It is a useful concept to keep in mind.
> --------------------------------------------------
> The "Swiss Army Knife (...Not)" API design pattern
> --------------------------------------------------
> This fortnight saw a number of different discussions on what Guido's  
> guiding principles are in making design decisions about Python. Guido  
> introduced the "Swiss Army Knife (...Not)" API design pattern, which  
> has been lauded by some as `the long-lost 20th principle from the Zen  
> of Python`_. A direct quote from Guido:
>      [I]nstead of a single "swiss-army-knife" function with various  
> options that choose different behavior variants, it's better to have  
> different dedicated functions for each of the major functionality types.
> This principle is the basis for pairs like str.split() and str.rsplit 
> () or str.find() and str.rfind().  The goal is to keep cognitive  
> overhead down by associating with each use case a single function  
> with a minimal number of parameters.

I think he made a more specific version of this rule: if you expect
people to usually pass in a constant for a parameter, define another
function. Booleans are especially good targets. For example, instead of

  str.find(x, y, fromright=False)
  str.find(x, y, fromright=True)


  str.find(x, y)
  str.rfind(x, y)


Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the Scipy-dev mailing list