3 ms·
> is that they interact very awkwardly with immutability How so? Tuples are awkward with immutability, if you put mutable things inside them.
by nomel 2y ago
> is that they interact very awkwardly with immutability
How so?
Tuples are awkward with immutability, if you put mutable things inside them.
- o11c 2y agoBy default, dataclasses can't be used as keys in a `dict`. You have to either use `frozen` (in which case the generated `__init__` becomes an abomination) or use `unsafe_hash` (in which case you have no guardrails). In languages with value semantics, nothing about this problem even makes sense, since obviously a dict's key is taken by value if it needs to be stored. -- Tuple behavior is sensible if you are familiar with discussion of reference semantics (though not as much as if you also support value semantics). Still, at least we aren't Javascript where the question of using composite keys is answered with "screw you".
- porridgeraisin 2y agoHaha obj[JSON.stringify(x)] = y * Ducks *
- o11c 2y agox = [Symbol('geese')]