I come to praise .join, not to bury it...

Barry A. Warsaw barry at digicool.com
Wed Apr 11 22:13:39 EDT 2001


>>>>> "I" == ISO  <juergen.erhard at gmx.net> writes:

    I> Sorry, Alex... but having read the discussions on python-dev,
    I> it doesn't seem like your "Guido has chosen" argument would
    I> fly.  It didn't seem to me like Guido `chose'... more like
    I> Barry did a patch which contained .join, and Guido approved the
    I> whole kit'n kaboodle...

    I> So, for me it looks much more like something like an accident
    I> than a well-reasoned decision (not the introduction of
    I> string-methods, but making .join a method of strings).

Not quite.  When the subject of string methods came up, we debated
what to do about string.join().  Tim Peters actually had the novel
suggestion of making it a method of the joiner, i.e. the string.  When
phrased as:

    SPACE = ' '
    SPACE.join(somelist)

it did, and still does, read very nicely to me, so I included it in
the string methods patch.  Guido at least didn't hate it, so it made
it in.  I will note that I almost always use the join method this way,
and almost never use it on a literal string; I agree that that looks
pretty ugly.

I won't rehash why join() isn't appropriate as a method of sequences,
but let me explain why I like it as a string method.  As a function in
the string module, the name `join' gives no clue as to whether the
sequence comes first and the joining string comes second, or vice
versa.  I often got it wrong, or had to look it up.  To me, that's a
pretty big Pythonic sin, and I don't like it.  As a method of a string
object, there's no confusion since there's only one argument, it has
to be the sequence.  This is the primary reason why I'm against making
join() a built-in.

It might have been better to rename the join method to something like
`joining' to give an even clearer cue.  SEPARATOR.joining(sequence)
reads quite well to me, and I'm sure we could come up with a few
alternatives.  It might be good to eventually add such a thing as an
alias for join, deprecating join's use, much like the old joinfields
and splitfields functions.

-Barry




More information about the Python-list mailing list