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

Alex Martelli aleaxit at yahoo.com
Mon Mar 5 04:57:03 EST 2001


"Delaney, Timothy" <tdelaney at avaya.com> wrote in message
news:mailman.983756766.27347.python-list at python.org...
    [snip]
> I truly have no complaints with the technical merits of ''.join().

Good.

> However, I have *severe* complaints with the aesthetics and consistency.
> Quite simply, the way we look at things tends to be
>
> "result" = "thing to be acted on to get the result" modified by "thing
which
> does the action"

This is bass-ackwards.  The 'thing which does the action', i.e. the
object which will house the method code, is the one that NEEDS to come
first, because of how dispatching is coded in the Python language!


> This is consistently followed in the standard python libraries in almost
all

We seem to be using two VERY different languages/libraries - funny
that they're both named 'Python', innit.  For example, in the Python
_I_ use, the re module defines objects (compiled regular expressions)
which are the 'things which do the action', and, sure enough, they
have methods which are passed the 'thing to be acted upon' as their
argument -- result = thing_doing_the_action.method(thing_acted_on).

Similarly, the pickle module defines objects (pickler objects) whose
methods are passed 'things to be acted upon' (e.g., a list to be
pickled can be passed to method dumps of the pickler, which returns
the result, a string).

And again, the urllib module defines object (URLopener objects)
whose methods are passed 'things to be acted upon' (e.g., open
is given a fullurl and optionally data) to return a result (here,
a file-like object).

And so on, and so forth.  It's really very consistent -- it HAS
to be, because it's mostly dictated by technical considerations
of 'which object do we need full polymorphism on, which one is
best handled through a standard interface instead'.

> cases ... but ''.join() is a glaring inconsistency. As a result, it seems
> unintuitive and ugly.

What inconsistency?!  It's exactly like the other cases -- the
object which does the action (here, a string-like object, who
works as a joiner) defines a method which is passed as argument
the object to be acted upon.


Alex






More information about the Python-list mailing list