String.join revisited (URGENT for 1.6)

Juergen A. Erhard jae at ilk.de
Sat Jun 3 15:54:26 EDT 2000


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Aahz" == Aahz Maruch <aahz at netcom.com> writes:

    Aahz> [cc'd to Guido for his delectation upon vacation return]
    Aahz> In article <03062000.1 at sanctum.jae.ddns.org>,
    Aahz> Juergen A. Erhard <jae at ilk.de> wrote:
    >> 
    >> It would seem (at least to me) to be the nicest (and cleanest) design
    >> to be able to do:
    >> 
    >> "some string".split().join()

    Aahz> That's what some people advocate, but that's semantically
    Aahz> equivalent to allowing [].join().  As has been pointed out
    Aahz> several times, adding a join() method to sequence types is a
    Aahz> Bad Idea.

I don't see why it should be a `Bad Idea'.  Or rather, I don't buy the
arguments put forward for calling it bad.

For one, in my original mail at the start of this thread I showed how
this could be done without `putting string knowledge into sequences'
(disregarding performance issues for now).

The other objection was that [].join would be 'lists and tuples are
*heterogeneous* containers. you can put *any* kind of Python object in
them, not just strings' (as quoted from a mail by the effbot).

Which is a non-argument... the exact same thing can be said against
string.join(list, sep).  So why should list.join(sep) not simply do
the same thing for non-strings that string.join(list, sep) does and
raise an TypeError exception?[1]

    Aahz> So far, nobody has pointed out *ANY* disadvantages of
    Aahz> retaining the current string.join() mechanism, with one
    Aahz> exception: it destroys the "orthogonality" of moving all
    Aahz> string functions to string methods.  Given that various
    Aahz> people have demonstrated that join() has disadvantages as a
    Aahz> method for both string or sequence types, I think
    Aahz> maintaining the 1.5.2 status quo is probably the best
    Aahz> option.

I repeat: none of the arguments against list.join really has any legs.
IMNSHO, of course.  When one day (in the hopefully not-so-distant
future) classes and types are merged, there (also hopefully) will be a
Sequence class that would be the ideal place for a .join method.

I'll shut up now ;-)

Bye, J

[1] The exact error is: "TypeError: first argument must be sequence of
strings".

- -- 
Jürgen A. Erhard      eMail: jae at ilk.de      phone: (GERMANY) 0721 27326
          My WebHome: http://members.tripod.com/Juergen_Erhard
             Internet Movie Database (http://www.imdb.com)
          Codito, ergo sum - I code, therefore I am -- Raster
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: Use Mailcrypt and GnuPG <http://www.gnupg.org/>

iEYEARECAAYFAjk5Ym8ACgkQN0B+CS56qs1VewCgmxv/Qfq0HhQx9xPvyXs6XUD4
VyoAn3tUly3MqE/exoigU6gHXzFJ5pnz
=3ezs
-----END PGP SIGNATURE-----




More information about the Python-list mailing list