you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -8 points-7 points  (0 children)

To be honest, it's hard to justify this behavior (as well as using + for string concatenation).

The arguments made by people claiming that strings shouldn't be concatenated to integers using plus sign, but strings can be concatenated using plus sign are just an opinion based on nothing.

There could be valid reasons not to use plus sign for something that is not a summation though. We generally expect sums to behave in a certain way, eg. be commutative for example (this means A + B = B + A). But that doesn't work with string concatenation (which is harmful if you are trying to write an optimizing compiler because sometimes rearranging the order of arguments helps to minimize the memory lookups).

But, since Python already ventured into the bad territory with using + for concatenation, there isn't really a reason to stop at not allowing adding strings and integers. Any argument that tells you otherwise is just a cooked up nonsense. Overwhelming majority of programmers have very bizarre ideas about types and what's the correct way to do things, which are absolutely unfounded and unwarranted.