No 1.6! (was Re: A REALLY COOL PYTHON FEATURE:)

François Pinard pinard at iro.umontreal.ca
Sat May 13 21:02:29 EDT 2000


"Magnus Lie Hetland" <mlh at idi.ntnu.no> writes:

> This is indeed a bit strange IMO... If I were to join the elements of a
> list I would rather ask the list to do it than some string... I.e.

>    ['foo', 'bar', 'baz'].join(', ')

Someone more knowledgeable than me could check, than confirm or inform.  I
think that usually, what was:

        string.FUNCTION(TEXT, ARG1, ARG2...)

in 1.5 can be written:

        TEXT.FUNCTION(ARG1, ARG2...)

in 1.6.  That is, the _first_ argument in the functional writing becomes
the object of the object-form writing.  The fact that we have:

        string.join(SEQUENCE [, TEXT])

with TEXT not being the first argument, and even optional, is the source of
the bizarreness.  It shows to me that the `join' method is not really meant
to be a string method, the string is just not the important object, here.
The 1.6 writing does not look neat, and I would rather see `join' as a
method of sequences, would it mean adding that method to all sequence types.
I would also much like that `TEXT' remains optional:

        SEQUENCE.join()

should return the string of sequence elements joined with spaces.  The fact
that that method returns a string is not a serious reason to make it a string
method.  A TYPE method does not have to return a TYPE object.  Many methods
return integers, tuples, or other things, this is not shocking at all.

        TEXT.join(SEQUENCE)

always looked pretty awkward to my eyes.  I hope Guido will revise this
before committing 1.6.  Else, it might soon become another lambda story! :-)

Maybe that part of the problem is that the meaning of the word `join' is
ambiguous, and disambiguated by prefixing it by `string'.  The original
problem might come from there: the prefixation is used in this case to
"explain" the word `join', much more than to say which kind of object is
mainly operated by the function.

This is at least my opinion.  We may disagree in various ways about what
should be best done, but one thing we are probably agreeing upon is that
having `join' as a method of string is not really proper.

P.S. - Does someone knows if Guido read this group?  If not, I would send
a copy of this letter directly to him.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list