string.join() syntax quirky?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Thu Nov 22 14:24:44 EST 2001


Thu, 22 Nov 2001 18:51:07 GMT, Erik Johnson <ejohnso9 at earthlink.net> pisze:

> is there a logical reason why it was implemented as a string method
> rather than a list method?

AFAIK because it's not necessarily a list but any sequence and we
don't want to require implementing join from all types which want
to behave like sequences. OTOH there are not many string-like types.

There also used to be some reasons concerning the dictinction between
byte strings and Unicode strings - AFAIR the separator used to decide
about the type of the result - but at least in Python 2.2 everything
is transparently recoded to Unicode when at least one of involved
strings is a Unicode string.

> Does it seem backwards to you or does it make intuitive sense to you?

It seems backwards for me - the sequence is more important than the
separator - but I wouldn't treat it as a list method either. More
as a global function.

But I'm strange in that I don't believe in OOP as a universal way
of life. At least the traditional OO view which makes an interface
of an operation dependant on which object is used to choose the
implementation.

The essence is that join doesn't need to be implemented separately
for various sequence types, and implementations for both flavors of
strings are already coupled.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^
QRCZAK



More information about the Python-list mailing list