I think the difference is that the convention in Java is to trust developers to not mutate map keys, while the convention in Python is to enforce this by always making mutable objects unhashable. For example, ArrayList in Java provides a value-based hash, while list in Python cannot be used as a dict key.
--David Chad Walters wrote: > I wonder if we are making too big a deal about this hashing issue for Python. > > How is the situation in Python really different from the situation in Java? > They seem very similar to me, but we don't seem to have a problem with > depending on the usage conventions in Java. > > Sorry If I am missing something obvious. > > Chad > > > On 10/19/08 8:39 AM, "Bryan Duxbury" <[EMAIL PROTECTED]> wrote: > > You mean that you could create a struct with a field that is > immutable, right? I assume that the way you'd create such immutable > objects is via the constructor only. Also, you'd just not have any > setters for that field, right? > > I'm not sure this would get you all the way to the hashability you're > looking for. Maybe it's just the terminology I'm thinking in is > different, but what you want is a run-time flag to set immutability, > not a compile-time immutable field. You'd do something like > myObj.setImmutable(), and it would make all the setters throw > exceptions, as well as have the sense to trickle down to all the > mutable subordinate objects. This approach wouldn't work in all > generators (default Java, for instance, since there ARE no setters, > just fields), but should work for most. > > -Bryan > > On Oct 19, 2008, at 5:57 AM, Esteve Fernandez wrote: > >> Hi all, what do you think about adding an "immutable" type >> modifier? Having >> immutable objects would make them hashable, thread-safe, etc. well, >> you >> already know the advantages. >> >> Cheers. > > >