3 ms·
Yeah, this is not a dict that has ordered keys. It's a dict that has that side effect. I can't think of any reason why a set's members, or a dict's keys (which
by a3n 10y ago
Yeah, this is not a dict that has ordered keys. It's a dict that has that side effect.
I can't think of any reason why a set's members, or a dict's keys (which are just set members with associated values, conceptually) should be unordered. Yes, set membership is traditionally unordered, but we have ordered sets and dicts, so they must be desirable, and they're certainly coherent.
I just hope that if sets and dicts become ordered by spec, that some day someone doesn't feel compelled to implement unordered versions.
- dragonwriter 10y ago> I just hope that if sets and dicts become ordered by spec, that some day someone doesn't feel compelled to implement unordered versions. Unspecified-order minimizes constraints on future implementations. If someone finds a useful time or space optimization (for particular workloads, not necessarily in big-O asymptotic terms) that isn't consistent with the specified ordering, that might be a compelling reason to implement a version without the ordering constraint. (But, if its not the best choice for general use, that's true even if the default implementation isn't ordered, since its possible that the optimization will still be unsuitable as the default.) And, obviously, even if the base case has one ordering, there's all kinds of reasons you might need to implement a version with a different ordering.
- pekk 10y ago"Ordered sets" are coherent in the sense that you can make a data structure like a set and then define an order over its members, and call it an ordered set, but "ordered sets" are not sets. There are certain purposes sets are natural for. When you introduce ordering, you will naturally be asked to add methods for querying or perhaps modifying that ordering in various ways. Many methods later, it's worth asking why you are calling this data structure a set, and what its actual purpose is supposed to be.