From: Aredridel Date: 2004-04-03T08:33:42+09:00 Subject: Re: deciding between ruby and python > Jim> I think Ville means that making join a method on a list means > Jim> that lists must now know about strings. Unfortunately, > Jim> removing join as a list method still leaves lists > Jim> knowledgeable about string for every object implements a to_s > Jim> method. > > I mostly meant that the sequence has a special case for the list of > strings. We have __str__ in Python too, but ''.join doesn't call it: > > >>> '-'.join([12,13]) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: sequence item 0: expected string, int found > > Calling to_s() seems kinda brutal from the Python POV. Perhaps this is > one of the areas where Ruby chooses the follow the Perl school of > Convenience. And it certainly is convenient: the following is hypothetical, but useful: class Socket def to_s "src: #{source}, dest: #{dest}" end end Then with an array of Sockets, you can do: [......].join("\n") src: 10.10.0.0 dest: 10.10.0.1 src: 10.10.0.0 dest: 10.10.0.2 Useful? The tradition of duck-typing and various kinds of hammer to coerce objects into acting like the appropriate types is an appealing part of Ruby. Ari