[Python-ideas] Why operators are useful

Kirill Balunov kirillbalunov at gmail.com
Sat Mar 16 09:29:43 EDT 2019


сб, 16 мар. 2019 г. в 16:02, Kirill Balunov <kirillbalunov at gmail.com>:

> Thank you for this very thoughtful message! It reminded me of my first
> experience with the old Fortran code. You probably know that earlier in
> Fortran there were no cryptic shortcuts for writing relational operators:
> instead of `A >= B`, you had to write `A .GE. B`, or as many often wrote
> this without spaces `A.GE.B`. Even after a decent time, I still mentally
> stop and linger on these places. It's amazing that, before your message, I
> never thought about the difference in perception between `>=` and `.GE.`.
> It seems to me that, from the perception point of view, the main difference
> is that `A .GE. B` consists of readable characters and therefore we try
> to read them, while `A >= B` is perceived as a single structure (picture)
> due to unreadable `>=`. And our brain is much more better at pattern
> matching than when reading. The same is true in Python in the difference
> between the operator and method forms: `a >= b` and `a.__ge__(b)`. If we
> draw an analogy for dictionaries between:
>
> a | b   # (my preference) over `a + b`   (1)
>
> and
>
> d = d1.copy()                            (2)
> d = d.update(d2)
>
>
of course

d = d1.copy()                            (2)
d.update(d2)

just copy-pasted your example without any thought:)


> The (1) is perceived as a picture, while (2) is perceived as a short
> story. And you have to read it, and spend some extra time, and spend some
> extra energy. English is not my mother tongue, so I'm not sure that my
> words correctly convey the meaning of the analogy.
>
> Offtopic: To be honest, the idea of `+` operator overloading for
> something non numeric still does not fully fit in my numerically oriented
> mind. If I started from the beginning, I would introduce a special dunder
> for concatenation (__concat__) with the corresponding operator, something
> like seq1 .. seq2 or seq1 ~ seq2. But that ship has long sailed.
>
> With kind regards,
> -gdg
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190316/8b7becc6/attachment.html>


More information about the Python-ideas mailing list