<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Honestly I don’t think "put it on PyPI" is a very useful thing in cases like<br>
these. Consuming a dependency from PyPI has a cost, such the same as dropping<br>
support for some version of Python has a cost. For something with an easy<br>
enough work around the cost is unlikely to be low enough for people to be<br>
willing to pay it.<br>
<br>
Python often gets little improvements that on their own are not major<br>
enhancements but when looked at cumulatively they add up to a nicer to use<br>
language. An example would be set literals, set(["a", "b"]) wasn't confusing<br>
nor was it particularly hard to use, however being able to type {"a", "b"} is<br>
nice, slightly easier, and just makes the language jsut a little bit better.<br>
<br>
Similarly doing:<br>
<br>
new_dict = dict1.copy()<br>
new_dict.update(dict2)<br>
<br>
Isn't confusing or particularly hard to use, however being able to type that<br>
as new_dict = dict1 + dict2 is more succinct, cleaner, and just a little bit<br>
nicer. It adds another small reason why, taken with the other small reasons,<br>
someone might want to drop an older version of Python for a newer version.<br>
<div class=""><div class="h5"><br>
---<br>
Donald Stufft<br>
PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA<br>
<br>
</div></div></blockquote><div><br></div><div>I'd expect the major constituency that would use an operator for this (especially over a function) is not well-represented on this list: students and newer users of python who just want to add two dictionaries together (they're probably also the ones upvoting that StackOverflow question). These people aren't going to download anything from PyPI; they probably don't know that PyPI exists, as I once didn't.<br><br>I don't think anyone seriously supports this proposal as a time-saver or code-elegancer for developers like ourselves: people who are Python experts and who develop large projects in Python. As demonstrated several times in this thread, most of us probably already have our own libraries of utility functions, and adding another one- or three-liner to these is easy for us. Adding this feature makes a much bigger difference for someone who's learning to program using Python, or who already knows some programming but is picking up Python as an additional langauge.<br><br></div><div>I see both positives and negatives to the proposal from this point of view. The positive would be ease of use. Python prides itself on being intuitive, and it really is much more intuitive in its basic everyday operation than other widespread languages like Java, in large part (IMO) because of its easy-to-use built-in default data structures. When I was learning Python, having already learned some C and Java, the idea of built-in list and dictionary data structures was an enormous relief. No more trying to remember the various methods of HashMap or ArrayList or worrying about which one I should be using where: these basic tools of programming just worked, and worked the way I'd expect, using very simple syntax. That was a big draw of the language, and I think the argument can be made here that adding a '+' operator for dictionaries adds to this quality of the language.<br><br></div><div>{ "a": 1, "b":2 } + { "c": 3}<br><br>is the kind of thing that I'd try to see if it worked *before* checking the docs, and I'd be pleased if it did.<br><br></div><div>That said, there's a negative here as well. The most obvious update procedure to me (others can argue about this if they wish) is overwriting keys from the lhs when a duplicate exists in the rhs. I think a big reason it seems obvious to me is that this is what I'd do if I had to implement such a function myself. But whatever resolution you have, it's going to catch people off-guard and introduce some low-visibility bugs into programs (especially the programs of the novices who I think are a big target audience of the idea). Of course, you could go with raising an error, but I don't think that's very productive, as it forces people to put a try/catch everywhere they'd use '+' which defeats the purpose of a simpler syntax in the first place.<br><br></div><div>Overall I guess I'm +0 on the proposal.<br></div><div>Most useful for novices who just want to add two dictionaries together already, but also potentially dangerous/frustrating for that same user-base.<br>A version that raised an exception when there was a key collision would be pretty useful for novices, but completely useless for experience programmers, as the overhead of a try/catch greatly outweighs the syntactic benefit of an operator.<br><br></div><div>-Peter Mawhorter<br></div></div></div></div>