[Python-ideas] textFromMap(seq , map=None , sep='' , ldelim='', rdelim='')

Boris Borcic bborcic at gmail.com
Tue Oct 26 16:32:10 CEST 2010


Nick Coghlan wrote:

>>> With the str method, while some
>>> people may find it odd to have the method invocation on the separator,
>>> they typically don't forget the order once they learn it for the first
>>> time.
>>
>> OTOH, it is a pain that join and split aren't *both* methods on the
>> separator. Imho, 71% of what makes it strange for join to be a method on the
>> separator, is that split doesn't follow the same convention.
>
> But split only makes sense for strings, not arbitrary sequences. It's
> the other way around for join.


I don't feel your "the other way around" makes clear sense. The /split/ function 
depends on two string parameters, what allows a design choice on which one 
should be the object when making it a method call. I have been burned more than 
once with internalizing that /join/ is a method on the separator, just to 
(re-)discover that such is *not* the case of the converse method /split/ - 
although it could (and therefore should, to minimize cognitive dissonance).

IOW, instead of whining that there is no way to make join a method on what "we 
should" think of as the prominent object (ie the sequence/iterator) and then 
half-heartedly promote sep.join as the solution, let's take the sep.join idiom 
seriously together with its implication that a core object role for a string, is 
to act as a separator.

And let's then propagate that notion, to a *coherent* definition of split that 
makes it as well a method on the separator.

Cheers, BB





More information about the Python-ideas mailing list