4 ms·
I'm amazed (and horrified) how come such an intelligent mathematician and designer of a beautiful programming language made such an obvious fuckup of using a co
by enriquto 8y ago
I'm amazed (and horrified) how come such an intelligent mathematician and designer of a beautiful programming language made such an obvious fuckup of using a commutative operator for string concatenation. Really, I hate python just for this single idiotic notation.
I mean, it's right there in front of your eyes. He talks about the convenience of using a visually commutative operator like "+" for commutative operations, and then a few lines later he says that it is a convenient notation for string concatenation. What. The. Fuck.
- _cs2017_ 8y agoI understand the confusion it may cause to a new Python developer who comes from the mathematical background. Does it cause any problems beyond that? For example, does it interfere with some elegant patterns, or result in some bug prone code, etc? FWIW, the single main annoyance I've had with python was its treatment of strings as iterables of single character strings. While not wrong in any obvious theoretical sense, it conflicts with the mental model of many developers (both new and experienced) and has probably caused more bugs than any other feature of Python (and even more ugly type checks to avoid such bugs). When people realized it was a problem and discussed removing this feature, Guido said he had tried but (a) it was too much work and (b) he felt the benefits are too great to give up (https://mail.python.org/pipermail/python-3000/2006-April/000824.html https://mail.python.org/pipermail/python-3000/2006-April/000...).
- zdkl 8y ago> strings as iterables of single character While it makes sense to think of them as sequences, this has bitten me more than I care to admit. OT: Is there a name for things we love to complain about, but wouldn't change?
- falcor84 8y agoYeah, it was a great mind-blown moment for me when I discovered that accessing the first character is idempotent in Python: s[0] == s[0][0][0][0]
- enriquto 8y ago> I understand the confusion it may cause to a new Python developer who comes from the mathematical background. I'm confused mainly because a person with a mathematical background created a language with such an obvious blunder. When I have to use the language (and I do often) I am not confused about string concatenation, I am ashamed of having to use this ridiculous notation.
- falcor84 8y agoI for one feel that + is a very intuitive choice for concatenating strings and lists. Is there any other common operator you would recommend instead? Because I feel that using a less common one would harm beginner-friendliness significantly. Also, to the best of my knowledge there is no place in the bible of maths that defines + to be commutative. In particular, addition of (infinite) ordinals is not commutative.
- enriquto 8y ago> I for one feel that + is a very intuitive choice for concatenating strings and lists. Is there any other common operator you would recommend instead? Literally, any other operator would be better than addition. A space, a dot, a product, two dots, a minus sign, whatever. Anything except the visually commutative plus. > Because I feel that using a less common one would harm beginner-friendliness significantly. Usage of + for string concatenation is fairly new, probably invented by C++ (which, by the way, uses bit shift operators for output, so it is not really an example of sane language).
- tomtimtall 8y ago“A”+”B” what do you feel should happen? “A”*6 what do you feel should happen?
- enriquto 8y ago> “A”+”B” what do you feel should happen? Clearly, that should be undefined. You cannot sum two strings. Unless you are really deranged and you want it to be "C".
- a1369209993 8y ago"A"+"B" = Regex("A|B") = Regex("[AB]") # or maybe "A"+"B" !> [?]Error: cannot convert /A|B/ to type str "A"*6 !> TypeError: <str> * <int>
- dragonwriter 8y ago> Because I feel that using a less common one would harm beginner-friendliness significantly. Actually, given that concatenating sequences (strings are an example) is a fairly common operation and for some kinds of sequences, so is adding them elementwise, it would be better not to use a common mathematical operator for concatenation, but to give it its own.
- peteradio 8y ago+ is a symbol not an operator. The operator is defined in how you implement. I think its quite a natural thing to use for string concatenation.
- enriquto 8y ago> I think its quite a natural thing to use for string concatenation. Some of you guys have really wicked minds.
- b_tterc_p 8y agoJulia does this with *. IMO it weirds people out
- enriquto 8y ago> Julia does this with * A much saner choice. I would prefer a space, still.
- emmelaich 8y agoWith stardot or just star? Yeah either would be a little weird. I'm asking partly because Ocaml uses stardot for floating point multiplication.
- ddragon 8y agoJust * "a" * "b" == "ab" "a" ^ 3 == "aaa" Though the dot version is actually almost possible because of a special syntax in Julia called broadcasting, which applies any function element-wise. "a" .* ["a", "b", "c"] == ["aa", "ab", "ac"] ["a", "b", "c"] .* "a" == ["aa", "ba", "ca"] ("a" * ["a", "b", "c"] would raise an error)
- _cs2017_ 8y agoHmm it does look like the other comment responding to you is correct: + is not always commutative in math: http://mathworld.wolfram.com/OrdinalAddition.html http://mathworld.wolfram.com/OrdinalAddition.html. If mathematicians are fine with that, I'm not sure what argument you may have against this operator being non-commutative in a programming language.