[Python-Dev] partition()

Raymond Hettinger raymond.hettinger at verizon.net
Tue Aug 30 17:11:53 CEST 2005


Hey guys, don't get lost in random naming suggestions (cut, snap, part,
parts, yada yada yada).  Each of those is much less descriptive and
provides less differentiation from other string methods.  Saving a few
characters is not worth introducing ambiguity.

Also, the longer name provides a useful visual balance between the three
assigned variables and the separator argument.  As an extreme example,
contrast the following:

   head, found, tail = s.p(separator) 
   head, found, tail = s.partition(separator)

The verb gets lost if it doesn't have visual weight.

Also, for those suggesting alternate semantics (raising exceptions when
the separator is not found), I challenge you to prove their worth by
doing all the code transformations that I did.  It is a remarkably
informative exercise that quickly reveals that this alternative is
dead-on-arrival.

For the poster suggesting an optional length argument, I suggest writing
out the revised method invariants.  I think you'll find that it snarls
them into incomprehensibility and makes the tool much more difficult to
learn.  Also, I recommend scanning my sample library code
transformations to see if any of them would benefit from the length
argument.  I think you'll find that it comes up so infrequently and with
such differing needs that it would be a mistake to bake this into the
proposal.



Raymond



More information about the Python-Dev mailing list