
On Oct 20, 2019, at 18:26, Steven D'Aprano <steve@pearwood.info> wrote:
but i'm -0 because i am very concerned it will not be obvious to new learners, without constantly looking it up, whether adding two mappings together would either:
When Python first added the dict.update method (I think that was in 1.5?) I could never remember if it kept the old values or the new. But there were a million other things I couldn't remember either, such as whether slicing was open or closed, whether the trig functions in math took degrees or radians, whether exponentiation was ^ or ** and whether I needed parentheses around calls to print or not.
Agreed. I know that in most of the languages I occasionally use, update/merge/+/|/<</addEntriesFromDictionary:/whatever preserves the right value, but at least one does the other. So whenever I go back to one of those languages after a while away from it, I have to look that up again. That’s unavoidable. Just as I have to look up how they spell it in the first place. And it’s already just as true for Python as it is for Ruby and ObjC and so on, because we already have update; people already have to learn that it uses the right value, and that it’s spelled update rather than merge! or something else. If we have + or |, people will have to learn that it uses the right value there too. The fact that all of the operations are consistent will mean that eventually they only have one thing to remember instead of a bunch of separate things, but it’s still a thing to remember. The only way around this is to provide a whole suite of operators for every variation (like Haskell), or to pass a function to make the choice explicitly (like Ruby). And even then, it doesn’t actually makes things easier to discover, or to remember, just more flexible. I know that I can both update preserving left and updating preserving right in Haskell, as well as a bunch of other variations, and the rules are nicely mnemonic while you’re using Haskell regularly, but if I haven’t used Haskell in a few months I still need to look up those rules and relearn them.