Live data from Hacker News

Why Operators Are Useful

neopythonic.blogspot.com

121–130 of 173 posts

Re: Why Operators Are Useful

#121
post #96

Earlier quoted context omitted.

If this is so obviously preferable, why have mathematicians so obdurately not adopted this style? Mathematical notation is not an archaic practice that is followed out of a respect for tradition, or a doctrine that has been developed from first principles, it is something that has evolved (and continues to do so) because it has been useful.

1. Mathematicians have different priorities than programmers, and they use different tools. Working with an equation on a whiteboard, it's easier to write "a+b+c" and then cancel terms as needed. When writing a formula on my computer, cancelling terms is something I almost never do, so it would be silly to use a notation that's been optimized for that. When I am doing algebra on my computer, I hope I have a tool like…

Σ is sum in Python and many other languages, and it's generalized across all binary operators via reduce.

Re: Why Operators Are Useful

#122
post #96

Earlier quoted context omitted.

If this is so obviously preferable, why have mathematicians so obdurately not adopted this style? Mathematical notation is not an archaic practice that is followed out of a respect for tradition, or a doctrine that has been developed from first principles, it is something that has evolved (and continues to do so) because it has been useful.

1. Mathematicians have different priorities than programmers, and they use different tools. Working with an equation on a whiteboard, it's easier to write "a+b+c" and then cancel terms as needed. When writing a formula on my computer, cancelling terms is something I almost never do, so it would be silly to use a notation that's been optimized for that. When I am doing algebra on my computer, I hope I have a tool like…

Most programming languages do have some variant of `sum(seqence)`. Python certainly does. Or, like, loops, which do the same thing.

But they're optimized for different things. Using the same tool for infinite length sequences and fixed length sequences doesn't make a whole lot of sense. We often have different types for them (tuple/record vs. list/array) too.

Re: Why Operators Are Useful

#123

Earlier quoted context omitted.

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

Indeed, Julia has the most well-thought-out commentary on strings in their docs I've seen from a non-toy language:

https://docs.julialang.org/en/v1/manual/strings/#man-concate...

Re: Why Operators Are Useful

#124
post #7

Earlier quoted context omitted.

Some would argue that the fact that you have all of those alternative forms is part of the problem. Lisp is one of the (if not the) most individualistic programming languages around. Lisp makes it easy for a programmer to create their very own impenetrable, arcane, domain specific languages. This causes large organizations to avoid it like the plague. Large teams don't want artists, they want replaceable parts.

Some would argue that Lego and Technic are too complicated, and we should all play with Duplo. Thankfully, Michelangelo and Leonardo were not in large teams. Which do you aspire to be: a cog or an artist?

If prefer it if the product of my engineering effort were maintainable and clear. I succeed if someone with no context can understand the system I built without help.

Re: Why Operators Are Useful

#125

A “dict” operator would be vague because there is more than one way to combine dictionaries. Why should I have to guess whether duplicate keys are being skipped or replaced by a symbol, when two different well-named functions will always make it clear?

You won't have to guess, it will be documented.

Documentation really isn’t a panacea. Quick, what exactly does this do: “UploadContent(false, true, true, false, false, false)”? Oh, all those flags are documented? Would you want to look them up every time?

Code should be more convenient to read before it is made more convenient to write.

Re: Why Operators Are Useful

#126

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

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

Re: Why Operators Are Useful

#127

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.

> I think its quite a natural thing to use for string concatenation.

Some of you guys have really wicked minds.

Re: Why Operators Are Useful

#128
post #59

But, this argument defeats itself. At least, in practice. If I look at how 'operator overloading' is used in practice, _rarely_ do you get commutativity, or even anticommutativity, associativity, or distributivity. Take list addition, where operator overloading often shows up: someList += someElement is shorthand for: someList.add(someElement) add is not commutative; the elements used in the operation aren't even the…

In my opinion, requiring commutativity from a +-operator is maybe too much. Associativity and a neutral element seem to be enough (i.e. forming a monoid).

> requiring commutativity from a +-operator is maybe too much

The + operator is the only one that can be realistically required to be commutative. All other operators need not. If we are to have any commutative operator, it should definitely be +.

Re: Why Operators Are Useful

#129

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

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

Re: Why Operators Are Useful

#130

Earlier quoted context omitted.

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

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

“A”+”B” what do you feel should happen? “A”*6 what do you feel should happen?
Post reply on HN