[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47
Skip Montanaro
skip at mojam.com
Tue Feb 22 16:01:07 EST 2000
bjorn> Exactly. Strings can't possibly know enough about all possible
bjorn> sequence types, including user defined ones, to make this
bjorn> efficient.
Why not? All "xyz".join needs to know is how to index into a sequence with
__getitem__ using an ever increasing integer series that begins at 0...
bjorn> Which is (a) a good argument for implementing join in the
bjorn> sequence types, since there are much more than *two* sequence
bjorn> types <wink> and (b) suggests that we really need a common base
bjorn> class for the sequence types to share common functionality
bjorn> (Python is an OO language after all...)
All sequence types know about __getitem__ (otherwise they wouldn't be
sequences). Conversely, you are asking that all sequences know enough about
strings (and eventually Unicode) to perform join, *and* you're asking the
same algorithm to be replicated in all sequences. (Will a join method
eventually be required for an object to be considered a sequence?)
bjorn> Conversely, to you really think that both string classes should
bjorn> know how to efficiently join all possible sequence types?
Again, knowing how to count using integers and call __getitem__ is all that
is required.
bjorn> sometimes implementing join as a series of concatenations does
bjorn> work, and is much easer than trying to implement __getitem__.
If it doesn't implement __getitem__, I don't think you can honestly call it
a sequence...
Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer
More information about the Python-list
mailing list