3 ms·
The dict example given is exactly why operators wouldn't be useful to me. Presumably d1 + d2 != d2 + d1 for some d1, d2. If you're going to use the + operator
by karmakaze 8y ago
The dict example given is exactly why operators wouldn't be useful to me.
Presumably d1 + d2 != d2 + d1 for some d1, d2.
If you're going to use the + operator then it should behave like it does in other contexts.
- hprotagonist 8y agothis is equally untrue true for strings, of course. “foo”+”bar” != “bar” + “foo” there are valid non-commutative additions.
- karmakaze 8y agoand is also a good reason to use a different operator for it too such as & or. and even space in some languages.
- hprotagonist 8y agoin the specific case of strings, my preferred way to spell that in python is f”{'foo'}{'bar'}”
- edflsafoiewq 8y agoAn interesting example is C's pointer-integer addition. p + n == n + p, true, but this is a purely syntactic fact. The actual semantic question of commutativity, whether switching the order of the arguments leaves the value unchanged, cannot even be asked of pointer-integer addition since the arguments, having differing types, cannot be switched.
- hcs 8y agoIndeed in C even array[index] is equivalent to index[array], just in case you want to be confusing.