PEP 218 Re: ANN: set-0.1 module available

Fernando Pérez fperez528 at yahoo.com
Fri May 17 20:07:45 EDT 2002


Erik Max Francis wrote:

> Sure, but when translating mathematical concepts to programming,
> practicality always gets in the way.  A dictionary, for instance, in
> essence just a function which maps a set into another.

And therefore means that the keys must never change, by the very definition of 
mapping. At a given value of the domain (the key) we have a value in the 
range (the value), and the domain value can't start jumping around. So for 
dictionaries thought as mappings, it's actually perfectly reasonable to 
expect the keys to be immutable.

For sets, on the other hand, it's a strange and unnatural restriction. Maybe 
for implementation reasons it will be practical to have them be _internally_ 
immutable and have them 'simulate' mutability like strings do (s = 'hi'; 
s+='ho' works 'in place' even though it doesn't ;)

Language design and implementation is always a balancing act: you want 
abstract, flexible and general features but you want them to be realistically 
implementable by normal humans in a finite amount of time. Where to draw the 
line is always a decision that involves as much gut and intuition as it does 
'science'. So far I think the python team has done an admirable job of 
finding a great balance. IMHO for sets, making them immutable would fall too 
far in the direction of 'practicality' and lose too much in the 'flexibility 
and power of abstraction' department. But again, that's my opinion.

Cheers,

f.



More information about the Python-list mailing list