[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47

Gordon McMillan gmcm at hypernet.com
Tue Feb 22 17:51:51 EST 2000


bjorn wrote:
> Gordon McMillan wrote:
> 
> > bjorn wrote:
> >
> > > I must respectfully disagree.  When doing OO design, the fundamental question
> > > is "if I want to do 'foo', to what am I doing 'foo'?"...  In this case "if I
> > > want to 'join', what am I 'joining'?", the answer is that you're joining a
> > > sequence type.  Thus, IMHO it the natural (and extensible to user types) way
> > > to do it would be:
> > >
> > >     [1,2,3].join()
> > >     (1,2,3).join(' ')
> >
> > string.join only works on lists of strings. If you introduce a
> > special "sequence of strings" type, then join could be a
> > method on that. Otherwise, you need to work out some new
> > semantics.
> 
> Sorry, bad example:
> 
>     ['a', 'b', 'c'].join()

You would put a method on sequence that only works if the 
sequence contains certain types? That's a really nasty 
precondition. Requiring the arg to string.join be a sequence 
containing only strings is a much saner precondition.

> > [snip]
> > But the scope here is the existing "string.join". The fact that
> > the procedural interface has the instance as the 2nd arg is a
> > distraction. It is a string method, not a list method.
> >
> > - Gordon
> 
> Just because it happened to be in the string module does not make it a string method
> (it's definitely possible, but one doesn't logically follow from the other). The
> fact that the string module interface has uses the second argument for the join
> field is pedagogically an important one.  E.g. the self parameter to a method is
> always passed first, and any of the ast/oo implementations in other procedural
> languages always pass the object being acted on as the first argument.  It therefore
> seems natural for a Python programmer to infer that join(seq, sep) should be parsed
> as seq.join(sep).

Does this mean that if I compile a C++ program with the 
Pascal calling convention, that it's no longer OO?
 
I guess we'll just have to change string.join to require the 
separator as the first argument. Or come up with a 
"homogeneous sequence" type, with a "joinable homogeneous 
sequence" subtype with an abstract join method.



- Gordon




More information about the Python-list mailing list