[Python-ideas] Why operators are useful

Rémi Lapeyre remi.lapeyre at henki.fr
Fri Mar 15 15:20:35 EDT 2019

 Le 15 mars 2019 à 18:52:51, Guido van Rossum
(guido at python.org(mailto:guido at python.org)) a écrit:


> The power of visual processing really becomes apparent when you combine multiple operators. For example, consider the distributive law:
> mul(n, add(x, y)) == add(mul(n, x), mul(n, y)) (5)
> That was painful to write, and I believe that at first you won't see the pattern (or at least you wouldn't have immediately seen it if I hadn't mentioned this was the distributive law).
> Compare to:
> n * (x + y) == n * x + n * y (5a)

Thanks for the insight. I think this omit a very important property of
mathematic equations thought, maths is a very strongly typed language
which can be a significant improvement for readability. For example, a
mathematician working within the space of linear maps over a vector
space will easily recognize the meaning of every symbol in:

f(a * x + y) = a * f(x) + f(y)

And know that the + in the above expression is very different from the
meaning of + in:

x = a * y + z

when he is working over the C complex field.

For example, he instinctively knows what 1 / z means in the second
case but that 1 / f in the first is completely bogus.

In Python there is not that much contextual information, but we can
use explicit names to overcome this, for example if I wrote:

o = d1 + d2 + d3

you would have no idea what this is but:

options = defaults + environment_variables + command_line_arguments

is meaningful.

> Of course, it's definitely possible to overdo this -- then you get Perl. But I think that the folks who point out "there is already a way to do this" are missing the point that it really is easier to grasp the meaning of this:
> d = d1 + d2
> compared to this:
> d = d1.copy()
> d = d1.update(d2)

Of course. I may have missed something but I don’t understand why
INADA Naoki proposal does not get more attention.

It is not binary, and we could use names to convey the meaning of the operation:

options = dict.merge(defaults, environment_variables, command_line_arguments)

His alternative options = defaults.merge(environment_variables,
command_line_arguments) could also be used if preferred.

Is there really something wrong with this? It would do exactly what
most proponent of + want but could be more readable.

I agree that the argument of performance may not be very strong as
most of the time, the updated dict might be smalls, but it would also
solved this elegantly.

I’m sorry if what I’m saying is not clear or I’m not able to convey my
thoughts clearly as English is not my mother tongue, many others are
better suited then me to discuss this proposal on this list but I
don’t understand why this possibility is not more discussed.


More information about the Python-ideas mailing list