lambda

Steve Holden steve at holdenweb.com
Mon Jan 17 09:45:51 EST 2005


Antoon Pardon wrote:

> Op 2005-01-17, Steve Holden schreef <steve at holdenweb.com>:
> 
>>Antoon Pardon wrote:
>>
>>
>>>Op 2005-01-17, Steve Holden schreef <steve at holdenweb.com>:
>>>
>>>
>>>>Antoon Pardon wrote:
>>>>[...]
>>>>
>>>>
>>>>>>"A foolish consistency is the hobgoblin of little minds". Rules are made 
>>>>>>to be broken.
>>>>>
>>>>>
>>>>>Like only use immutables as dictionary keys.
>>>>>
>>>>
>>>>Fair enough, but don;t go advising newbies to do this.
>>>
>>>
>>>How about something like this.
>>>
>>>Because of the extra precautions one has to take when
>>>using mutables as hash keys, we advise newbies
>>>to stick with immutable keys until they have gathered
>>>enough knowledge and experience to adequatly weight
>>>the pro and cons of a mutable key solution against
>>>an immutable key solution.
>>>
>>
>>There you go with the minutiae again. How about:
>>
>>"Don't use mutables as hash keys"?
> 
> 
> That sounds too dogmatic to my ears. I also find it
> too selective. The problem with mutables as dictionary
> keys is not specific to dictionaries. Everywhere you
> have mutables in a container, it is possible that
> mutating the object in the container will cause
> problem. Heck even using mutables as arguments can
> cause trouble. Why else the specific advice against
> 
>   def foo(p = [])
> 
> type of arguments. So should we adopt the principles:
> 
>   Don't use mutables in containers
> 
>   Don't use mutables as default values for parameters
> 
>   Don't use mutables as arguments.
> 
>   Don't assign one mutable to an other.
> 
> 
> I don't see a big difference between these principles
> and the hash key principle, so in the end may be we
> should just stick with the more general principle:
> 
>   Don't use mutables!
> 
> 
> and be done with it.
> 
http://redwing.hutman.net/~mreed/warriorshtm/tirelessrebutter.htm

regards
  Steve
-- 
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119



More information about the Python-list mailing list