tuples, index method, Python's design

Antoon Pardon apardon at forel.vub.ac.be
Thu Apr 12 03:37:38 EDT 2007


On 2007-04-11, Chris Mellon <arkanes at gmail.com> wrote:
> On 11 Apr 2007 08:37:39 -0700, Paul Boddie <paul at boddie.org.uk> wrote:
>> On 11 Apr, 16:14, "Chris Mellon" <arka... at gmail.com> wrote:
>> >
>> > If you want a language that just adds whatever methods anyone thinks
>> > of, along with whatever aliases for it any can think of, to every data
>> > type, you know where to find Ruby.
>>
>> Nobody is asking for Ruby, as far as I can see. I even submitted a
>> quick patch to provide tuple.index (a method that has already been
>> thought of), given the triviality of the solution, but you won't find
>> me asking for a bundle of different convenience methods with all their
>> aliases on every object, regardless of whether you can monkey-patch
>> them after the fact or not. For example:
>>
>
> Note that the mail I responded to was using being drunk, not knowing
> any better, and having fun as use cases for the method. That sounds
> like Ruby-style method proliferation to me ;)
>
>
>> Note that, in that document, index and count are methods of
>> MutableSequence. Quite why this should be from a conceptual
>> perspective is baffling, but don't underestimate the legacy influence
>> in such matters.
>>
>
> Well, I'm not Guido obviously, but here's why I don't find it baffling.
>
> There are 2 main reasons why you'd use an immutable sequence for something:
> 1) You want to make sure it's not modified by a callee. This is
> unPythonic and mostly unnecessary. Pass them a copy if you're that
> paranoid.

Why then does python itself provide immutables? I find this reasoning
more than baffling. There has been all these arguments about why
it is best to use immutables as dictionary keys. But the moment
the topic changes, someone else comes with the comment that
wanting your sequence to be immuatble is unpythonic.

I once had a problem I like to solve by having a dictionary
where the keys were multidimensional points on an integer grid.
For a number of reasons I thought it would be easier if I could
use lists, but most people argued that would be a bad idea and
that I should use tuples, because they are immutable.

Of course if I now would want to find out if the point is on an
axis and which axis that is, I cannot use index because that is
not available. 

-- 
Antoon Pardon



More information about the Python-list mailing list