Live data from Hacker News

Why Operators Are Useful

neopythonic.blogspot.com

111–120 of 173 posts

Re: Why Operators Are Useful

#111

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 operation…

+ 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.

Re: Why Operators Are Useful

#112

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 operation…

I 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…

> 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?

Re: Why Operators Are Useful

#114

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 operation…

Julia does this with *.

IMO it weirds people out

Re: Why Operators Are Useful

#115

I've grown to dislike operator overloading quite a bit, and thus developed a general skepticism with regard to operators in general, and I think this article actually reveals why partially. First off, I'm surprised this article doesn't touch at all on the fact that operators are usually the only "blessed" functions in languages to be able to be written in infix form, as I think that's actually where many of the "bene…

The best part is that string concatenation is a perfectly cromulent "multiplication", forms a free monoid, and in line with some notations for concatenation of tuples.

Funny the associations we make...

Re: Why Operators Are Useful

#116
post #23
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

This is a non-problem in every language with variadic functions. "add(x, y, z)" looks good to me.

You have to be careful though. In Julia, there is "fma(a,b,c)" which is not necessarily the same as "muladd(a,b,c)".

What are the guarantees on add(a,b,c) versus a+b+c?

If do add(1.0e30, 1.0, -1.0e30) is that the same (aka IEEE fp addition is noncommutative)

Re: Why Operators Are Useful

#117

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 operation…

I 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…

Yeah, 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]

Re: Why Operators Are Useful

#118

Earlier quoted context omitted.

What? Have you never had two dicts and wanted vals from one dict override the other?

If a+b != b+a that breaks the commutativity property of addition.

To be fair, IEEE fp addition is noncommutative in corner cases.

Re: Why Operators Are Useful

#119

I've grown to dislike operator overloading quite a bit, and thus developed a general skepticism with regard to operators in general, and I think this article actually reveals why partially. First off, I'm surprised this article doesn't touch at all on the fact that operators are usually the only "blessed" functions in languages to be able to be written in infix form, as I think that's actually where many of the "bene…

The best part is that string concatenation is a perfectly cromulent "multiplication", forms a free monoid, and in line with some notations for concatenation of tuples. Funny the associations we make...

Well that's exactly why string concat in Julia is

Re: Why Operators Are Useful

#120

Earlier quoted context omitted.

If a+b != b+a that breaks the commutativity property of addition.

That property is not universal, and it is currently being defined for Python dictionaries. You can't break a property that isn't defined yet. ;-)

Is this what changed in 3.5?
Post reply on HN