3 ms·
> do you think of addition when you see `string + "concatenate"` Yes. And it tortures me every time. I religiously avoid string concatenation in Python for t
by enriquto 3y ago
> do you think of addition when you see `string + "concatenate"`
Yes. And it tortures me every time.
I religiously avoid string concatenation in Python for this very reason. It's not that "+" necessarily means addition; it's that it always means a commutative operation (to somebody who has learned some algebra). String concatenation is notoriously non-commutative, thus it is extremely disturbing to write it using a visibly commutative operator. Any other operator except "+" would be better. For example, a space, or a product, or a hyphen. Whatever. But please, not a commutative operator. It breaks my brain parser.
- panza 3y agoThis is a really good point. It bothers me too, but I hadn't really articulated why.
- Dylan16807 3y agoIt's also one of the biggest sources of bugs when dealing with loose types around strings and numbers. When it comes to languages that let you mix strings and numbers, Lua has it right. + always adds, and accepts numbers and strings that can cleanly convert to numbers. .. always concatenates, and accepts numbers and strings.